生成條形碼 (jsbarcode)
- 安裝包
npm i jsbarcode --save
- 使用
<div class="barcode-box">
<img id="barcode" />
</div>
<script>
import JsBarcode from 'jsbarcode'
export default {
data() {
return {
},
created () {
// 生成條形碼
this.$nextTick(() => {
// 待生成條碼的內(nèi)容
JsBarcode('#barcode', '123')
})
},
};
</script>
生成二維碼(qrcodejs2 )
- 安裝包
npm i qrcodejs2 --save
- 使用
<div class="qrcode" ref="qrCodeUrl"></div>
<script>
import QRCode from 'qrcodejs2'
export default {
data() {
return {
},
methods: {
creatQrCode() {
var qrcode = new QRCode(this.$refs.qrCodeUrl, {
text: '123456', // 待生成為二維碼的內(nèi)容
width: 100,
height: 100,
colorDark: '#000000',
colorLight: '#ffffff',
correctLevel: QRCode.CorrectLevel.H
})
},
},
mounted() {
this.creatQrCode();
},
};
</script>