javascript - vue引入微信jssdk 配置在哪個生命周期調取接口配置?
問題描述
在ios中會報 invalid signature的錯誤,安卓就沒事, 微信開發者工具里面也沒事 在create beforecreate mounted中都嘗試做wx.ready但是總是報invalid signature。 關閉這個alert之后微信的接口可以用,如果encodeURIcomponent在調取后臺接口的時候就直接報錯了,后臺接口日志在前端沒有encode的時候參數也是encode之后的樣式。請教各位 這是什么原因導致的呢。
問題解答
回答1:關于微信簽名錯誤,請參考官方文檔,具體問題具體分析,按步驟仔細排查.然后關于初始化微信,如單組件使用在mounted中聲明更加,也可在main.js中全局聲明.貼上我抽出的一般性代碼:
export default { init() { let that = this; Service.wxConfig({//調用服務端獲取簽名配置url: location.href.split(’#’)[0] }, result => {if (result.success) { that.weixinConfig(result.data);} }); }, weixinConfig(data) { wx.config({debug: false,appId: data.appId,timestamp: data.timestamp,nonceStr: data.nonceStr,signature: data.signature,jsApiList: [ ’onMenuShareTimeline’, ’onMenuShareAppMessage’, ’showOptionMenu’, ’hideOptionMenu’, ’showMenuItems’, ’hideMenuItems’, ’chooseImage’, ’previewImage’, ’uploadImage’, ’chooseWXPay’] }); }}
相關文章:
1. php - mysql 模糊搜索問題2. 請問連接文件怎么寫3. 求救一下,用新版的phpstudy,數據庫過段時間會消失是什么情況?4. php - 微信開發驗證服務器有效性5. python沒入門,請教一個問題6. 小程序怎么加外鏈,語句怎么寫!求救新手,開文檔沒發現7. [python2]local variable referenced before assignment問題8. javascript - 我的站點貌似被別人克隆了, google 搜索特定文章,除了域名不一樣,其他的都一樣,如何解決?9. javascript - js setTimeout在雙重for循環中如何使用?10. javascript - 求幫助 , ATOM不顯示界面!!!!
