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. mysql - select查詢多個紀錄的條件怎么寫2. mysql 獲取時間函數unix_timestamp 問題?3. Mysql 關于 FOUND_ROWS() 和 ROW_COUNT() 函數4. 這段代碼是獲取百度收錄量的!需要怎么設置才能獲取百度快照旁邊的網址呢?5. dockerfile - 我用docker build的時候出現下邊問題 麻煩幫我看一下6. html5 - 基于vue的圖片查看,如何實現?7. java - android使用websocket無法訪問cookie。8. docker綁定了nginx端口 外部訪問不到9. javascript - es6數值解構Number.prototype.toString is not generic10. vue.js - vue 打包后 nginx 服務端API請求跨域問題無法解決。
