分享接口只有认证公众号才能使用,域名必须备案且在微信后台设置。
\n先确认已经满足使用jssdk
的要求再进行开发。
WechatPlugin
插件提供了commonJS
的引入方式,因此你不需要在 index.html
引入文件。
WechatPlugin
在vux@^2.1.0-rc.19
开始支持
在 main.js
中全局引入:
import { WechatPlugin } from 'vux'\nVue.use(WechatPlugin)\n\nconsole.log(Vue.wechat) // 可以直接访问 wx 对象。\n
\n考虑到你需要在引入插件后调用config
方法进行配置,你可以通过 Vue.wechat
在组件外部访问wx
对象。
jssdk
需要请求签名配置接口,你可以直接使用 VUX 基于 Axios
封装的 AjaxPlugin
。
import { WechatPlugin, AjaxPlugin } from 'vux'\nVue.use(WechatPlugin)\nVue.use(AjaxPlugin)\n\nVue.http.get('/api', ({data}) => {\n Vue.wechat.config(data.data)\n})\n
\n那么之后任何组件中都可以通过 this.$wechat
访问到 wx
对象。
export default {\n created () {\n this.$wechat.onMenuShareTimeline({\n title: 'hello VUX'\n })\n }\n}\n
\n