赞
踩
经过查阅官方文档,发现钉钉应用开发平台和uniApp的返回值不一样!!(头大,为什么还没有统一),扫码的方法如下:
let that = this;
uni.scanCode({
// onlyFromCamera: true,
success: function (res) {
uni.showToast({
title: ‘扫码成功’,
duration: 1000
});
that.inputClearValue = JSON.parse(JSON.stringify(res)).result;
},
fail: (err) => {
// 扫码失败的逻辑处理
uni.showToast({
title: ‘扫码失败’,
duration: 1500
});
}
});
let that = this;
dingtalk.biz.util.scan({
type: ‘all’, // type 为 all、qrCode、barCode,默认是all。
onSuccess: function (data) {
uni.showToast({
title: ‘扫码成功’,
duration: 1000
});
that.inputClearValue = JSON.parse(JSON.stringify(data)).text;
},
onFail: function (err) {
uni.showToast({
title: ‘扫码失败’,
duration: 1500
});
}
})
特别注意:(1)uni的扫码方法是内置的scanCode
方法,钉钉是biz.util.scan
,两者都需要我们进行安装引用(2)this
的指向问题,在内置的方法里,this是获取不到的,要用that
代替!(3)看到两者的差异,钉钉的返回内容是用test
拿到,而uni是用result
,当然两者返回的都是[object Obejct],需要我们用json
进行转换。
好了,到此为止,希望可以帮到你处理一些问题,记得点赞收藏哟,亲!
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。