直接写成组件
<template>
<div>
<div ref="qrcode"></div>
</div>
</template>
<script>
import QRCode from 'qrcodejs2'
export default {
name: "PrintQrCode",
props: {
text: {
required: true,
default: null
},
width: {
type: Number,
required: false,
default: 84
},
height: {
type: Number,
required: false,
default: 84
}
},
data() {
return {
count: null,
data: null
}
},
mounted() {
this.qrcode();
},
methods:{
qrcode() {
let qrcode = new QRCode(this.$refs.qrcode, {
width: this.width,
height: this.height,
text: this.text, // 二维码地址
colorDark : "#000",
colorLight : "#fff",
correctLevel : QRCode.CorrectLevel.L
})
},
}
}
// correctLevel 容错级别,可设置为:
// QRCode.CorrectLevel.L
// QRCode.CorrectLevel.M
// QRCode.CorrectLevel.Q
// QRCode.CorrectLevel.H
// L - M - Q - H 码密度越来越高,默认不设置是用 H H有时候扫不出来
</script>