效果图:
实现代码:
<template>
<view>
<view v-if="result">{{ result }}</view>
<button type="primary" @click="scan">扫一扫</button>
</view>
</template>
<script>
export default {
data() {
return {
title: 'scanCode',
result: ''
};
},
methods: {
async scan() {
uni.scanCode({
success: res => {
this.result = res.result;
},
fail: err => {
// 需要注意的是小程序扫码不需要申请相机权限
}
});
}
}
};
</script>