该方法需引入微信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列表
}
});
});
})
},