39 lines
785 B
Vue
Raw Normal View History

2025-04-14 10:57:27 +08:00
<template>
<view>
<uni-easyinput class="uni-mt-5" @blur="onInput" v-model="code" :placeholder="placeholder" suffixIcon="scan"
@iconClick="onScan">
</uni-easyinput>
</view>
</template>
<script setup>
const code = defineModel({
type: String
});
const props = defineProps(["placeholder"]);
const emit = defineEmits(['scan-change']);
//扫描
const onScan = () => {
uni.scanCode({
onlyFromCamera: true, //只能扫码
scanType: ["qrCode"],
success(res) {
const {
result
} = res;
code.value = result;
emit('scan-change', result);
},
fail(res) {}
})
};
const onInput = (value) => {
if (value.detail.value == "") return;
code.value = value.detail.value;
emit('scan-change', value.detail.value);
}
</script>
<style>
</style>