小例子:
templateviewbutton type="primary" @click="tel()"button/button/view/templatescriptexport default {data() {return {};},methods:{tel:function(){uni.scanCode({success:function(res){console.log(JSON.stringify(res));}});}}}/scriptstyle/style
uni.scanCode(OBJECT)
调起客户端扫码界面,扫码成功后返回对应的结果。
平台支持度
5+App | H5 | 微信小程序 | 支付宝小程序 | 百度小程序 | 头条小程序 |
---|---|---|---|---|---|
√ | x | √ | √ | √ | √ |
OBJECT 参数说明
参数名 | 类型 | 必填 | 说明 | 平台支持度 |
---|---|---|---|---|
onlyFromCamera | Boolean | 否 | 是否只能从相机扫码,不允许从相册选择图片 | 头条小程序不支持 |
scanType | Array | 否 | 扫码类型,参数类型是数组,二维码是'qrCode',一维码是'barCode',DataMatrix是‘datamatrix’,pdf417是‘pdf417’。 | 头条小程序不支持 |
success | Function | 否 | 接口调用成功的回调,返回内容详见返回参数说明。 | |
fail | Function | 否 | 接口调用失败的回调函数 | |
complete | Function | 否 | 接口调用结束的回调函数(调用成功、失败都会执行) |
success 返回参数说明
参数 | 说明 | 平台支持度 |
---|---|---|
result | 所扫码的内容 | |
scanType | 所扫码的类型 | 5+App、微信小程序、百度小程序 |
charSet | 所扫码的字符集 | 5+App、微信小程序、百度小程序 |
path | 当所扫的码为当前应用的合法二维码时,会返回此字段,内容为二维码携带的 path。 | 5+App、微信小程序、百度小程序 |
官网:https://uniapp.dcloud.io/api/system/barcode