
简体中文
扫码
Web | 微信小程序 | Android | Android uni-app x UTS 插件 | iOS | iOS uni-app x UTS 插件 | HarmonyOS |
---|---|---|---|---|---|---|
x | 4.41 | x | x | x | x | 4.61 |
App平台暂未内置,见插件市场
名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 | ||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options | ScanCodeOptions | 否 | - | - | uni.scanCode参数定义 | ||||||||||||||||||||||||||||||||||||
|
名称 | 类型 | 必备 | 默认值 | 兼容性 | 描述 |
---|---|---|---|---|---|
result | string | 是 | - | - | - |
scanType | string | 是 | - | - | - |
charSet | string | 否 | - | 所扫码的字符集 | |
path | string | 否 | - | 当所扫的码为当前小程序二维码时,会返回此字段,内容为二维码携带的 path | |
rawData | string | 否 | - | 原始数据,base64编码 |
该 API 不支持 Web,请运行 hello uni-app x 到 App 平台体验
<template>
<view>
<page-head :title="title"></page-head>
<view class="uni-padding-wrap uni-common-mt">
<view class="uni-title">扫码结果:</view>
<view v-if="result" class="scan-result">
{{result}}
</view>
<view class="uni-btn-v">
<button type="primary" @click="scan">扫一扫</button>
</view>
</view>
</view>
</template>
<script lang="uts">
export default {
data() {
return {
title: 'scanCode',
result: ''
}
},
methods: {
scan() {
uni.scanCode({
success: (res: ScanCodeSuccess) => {
console.log('res: ',res);
this.result = res.result
},
fail: (err: ScanCodeFail) => {
console.log('err: ',err);
// 需要注意的是小程序扫码不需要申请相机权限
}
});
}
}
}
</script>
<style>
.scan-result {
min-height: 50rpx;
line-height: 50rpx;
}
</style>
该 API 不支持 Web,请运行 hello uni-app x 到 App 平台体验
<template>
<view>
<page-head :title="title"></page-head>
<view class="uni-padding-wrap uni-common-mt">
<view class="uni-title">扫码结果:</view>
<view v-if="result" class="scan-result">
{{result}}
</view>
<view class="uni-btn-v">
<button type="primary" @click="scan">扫一扫</button>
</view>
</view>
</view>
</template>
<script lang="uts">
export default {
data() {
return {
title: 'scanCode',
result: ''
}
},
methods: {
scan() {
uni.scanCode({
success: (res: ScanCodeSuccess) => {
console.log('res: ',res);
this.result = res.result
},
fail: (err: ScanCodeFail) => {
console.log('err: ',err);
// 需要注意的是小程序扫码不需要申请相机权限
}
});
}
}
}
</script>
<style>
.scan-result {
min-height: 50rpx;
line-height: 50rpx;
}
</style>
名称 | 类型 | 必备 | 默认值 | 兼容性 | 描述 |
---|---|---|---|---|---|
errMsg | string | 是 | - | 错误信息 |