vue下的微信web jssdk

  1. npm install weixin-js-sdk --save
  2. 在 main.js 或 App.vue 中
  • 注意url为encodeURI(location.href.split('#')[0]),只须要#以前的内容,且必须encodeURI处理,所以使用vue-router的hash模式只须要config一次,而使用history模式则须要每一个页面都config

上面说法有误,在ios下只需config一次,但在安卓下,一旦使用了浏览器自带的回退,就须要从新configjavascript

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)
})
相关文章
相关标签/搜索