1、安装
npm install weixin-js-sdk -S
2、引入
import wx from 'weixin-js-sdk'
3、调用
methods: {
async takePhoto ( ) {
let that = this
Toast( '正在调起扫描功能' )
// 拿到配置信息
let res = await this.GetSMConfig( setting.base + '/about' )
if ( res.code == = 0 ) {
wx.config( {
// 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
debug: false,
// 必填,公众号的唯一标识
appId: res.data.appId,
// 必填,生成签名的时间戳
timestamp: res.data.timestamp,
// 必填,生成签名的随机串
nonceStr: res.data.nonceStr,
// 必填,签名
signature: res.data.signature,
// 必填,需要使用的JS接口列表,所有JS接口列表
jsApiList: [ 'checkJsApi' , 'scanQRCode' ]
} )
wx.ready( function ( ) {
wx.checkJsApi( {
jsApiList: [ 'scanQRCode' ] ,
success: function ( res) {
}
} )
wx.scanQRCode( {
needResult: 1 , // 默认为0,扫描结果由微信处理,1则直接返回扫描结果,
// scanType: [ 'qrCode' ] , // 可以指定扫二维码还是一维码,默认二者都有
success: function ( res) {
var result = res.resultStr // 当needResult 为 1 时,扫码返回的结果
}
} )
} )
}
} ,
}