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) })