微信公眾號介面呼叫JS-SDK(vue專案,以掃一掃為例)
阿新 • • 發佈:2018-12-04
該方法需引入微信js-sdk ,先npm安裝
//在一個地方呼叫this.weixin()方法,比如說按鈕 //寫掃一掃方法 weixin() { var that = this; var url=''; var params = { ..... }; axios.post(url,params).then((res) => { var resulted = res.data.data; that.wxConfig = resulted; that.$wx.config({ debug: false, appId: that.wxConfig.appid, timestamp: that.wxConfig.timestamp, nonceStr: that.wxConfig.noncestr, signature: that.wxConfig.signature, // 所有要呼叫的 API 都要加到這個列表中 //要呼叫的微信介面 jsApiList : [ 'checkJsApi', 'startRecord', 'stopRecord', 'translateVoice', 'scanQRCode', 'openCard' ] }); that.$wx.ready(function() { that.$wx.scanQRCode({ needResult: 1, // 預設為0,掃描結果由微信處理,1則直接返回掃描結果, scanType: ["qrCode", "barCode"], // 可以指定掃二維碼還是一維碼,預設二者都有 success: function(res) { var objdata= res.resultStr; // 當needResult 為 1 時,掃碼返回的結果 that.text_search = objdata.assetqrcode that.getAllTableData(that.text_search)//獲取想要獲取的資料,比如說table列表 } }); }); }) },