注意:
// npm install qrcodejs2
安装后报错:TypeError:Cannot read properties of undefined(reading‘_android‘)
没找到解决办法,重装了下面的
// npm install qrcodejs2-fix
使用
<template>
<div class="qrCode" :id="el"></div>
</template>
<script setup>
// import QRCode from 'qrcodejs2-fix'
import QRCode from 'qrcodejs2-fix'
import { computed, onMounted, nextTick } from 'vue'
const props = defineProps({
el: {
type: String,
required: true
},
options: {
type: Object,
required: false
}
})
const currentEl = computed(() => props.el)
console.log(currentEl.value, 'currentEl')
onMounted(() => {
nextTick(() => {
autQRCode()
})
})
const autQRCode = () => {
let {
text = '二维码',
width = 200,
height = 200,
colorDark = '#333333',
colorLight = '#ffffff',
correctLevel = QRCode.CorrectLevel.L
} = props.options
const qrcode = new QRCode(currentEl.value, {
text,
width,
height,
colorDark, //二维码颜色
colorLight, //二维码背景色
correctLevel //容错率,L/M/H})
})
console.log(qrcode, 'qrcode')
return qrcode.value
}
</script>