在vue移动端开发时,很多时候需要调用手机底层的一些功能来实现业务,所以在使用Hbuilder打包的前提下调用Hbuilder的二维码plus模块 来实现
二维码扫描功能,二维码的状态和使用最好在vuex中赋值,以方便控制。
在mounted阶段调用下面代码片段
startRecognize(){
let that = this
if (!window.plus) return
// 使用vuex来创建scan二维码
that.$store.commit('changescan', new plus.barcode.Barcode('qrcode'))
// 设置扫描之后的函数回调
that.$store.commit('changeonmarked',onmarked)
// 开始扫描
that.$store.commit('staticScan')
//设置扫描二维码页面样式,根据需求自行调整
barcode.setStyle({
background:'#8f9494',
height:"100%"
});
//成功之后的函数回调
function onmarked(type, result, file) {
switch<