Micro-channel under vue web jssdk

  1. npm install weixin-js-sdk --save
  2. In main.js or in App.vue
  • Note url is encodeURI(location.href.split('#')[0]), only # before the content, and must encodeURI treatment, the use of hash vue-router config mode only once, and use history mode which requires each page config
import wx from 'weixin-js-sdk';
https.fetchGet('/WeixinJSSDK/GetWeishopJsViewModel', {
  tenantId: 5056,
  memberId: memberId,
  url: encodeURI(location.href.split('#')[0])
}, 'G').then((data) => {
  wx.config({
    debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
    appId: data.appId, // 必填,公众号的唯一标识
    timestamp: data.timestamp, // 必填,生成签名的时间戳
    nonceStr: data.nonceStr, // 必填,生成签名的随机串
    signature: data.signature,// 必填,签名
    jsApiList: ['onMenuShareTimeline', 'onMenuShareAppMessage', 'chooseImage', 'uploadImage'] // 必填,需要使用的JS接口列表
  });
  wx.ready(function () {
    console.log('wx.config')
  })
}).catch(err => {
  console.log(err)
})

Reproduced in: https: //www.jianshu.com/p/8e0e997dc70e

Guess you like

Origin blog.csdn.net/weixin_34066347/article/details/91061111