h5使用wx.scanQRCode,需配置wx.config

安装 weixin-js-sdk

npm install weixin-js-sdk --save

mian.js中引入'weixin-js-sdk'

import wx from 'weixin-js-sdk'
Vue.prototype.$wx = wx

页面中配置wx.config

onLoad() {
	this.getCofig();
},
methods: {
 getCofig() {
			let url = '';
			url = window.location.href.split('?')[0]; //url是当前页面的域名
			console.log(window.location.href,url)
			this.$api.getData(`sys/getSignature?signatureUrl=${url}`).then(res=>{
				if(res.success){
					const data = res.result
					Vue.prototype.$wx.config({
						debug: false, // 开启调试模式,
						appId: 'wwxxxxxxx', // 必填,企业号的唯一标识
						timestamp: data.timesTamp, // 必填,生成签名的时间戳
						nonceStr: data.noncestr, // 必填,生成签名的随机串
						signature: data.signature, // 必填,签名
						jsApiList: ['scanQRCode', 'checkJsApi'], // 必填,需要使用的JS接口列表
					});
					Vue.prototype.$wx.ready(() => {
						console.log('配置完成,扫码前准备完成')
					})
					Vue.prototype.$wx.error(function (res) {
						console.log('出错了:' + res.errMsg); //wx.config配置错误,会弹出窗口哪里错误,然后根据微信文档查询即可。
					});
				}
			})
		},
}

使用扫码功能

Vue.prototype.$wx.scanQRCode({
	needResult: 1,
	success: function(res) {
	  console.log(res.resultStr)
    }
});

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值