1、安装qrcodejs2
npm install qrcodejs2 --save
2、组件中引用
import QRCode from 'qrcodejs2'
3、使用
<div class="qrCode" ref="qrCodeDiv"></div>
methods(){
bindQRCode () {
this.$refs.qrCodeDiv.innerHTML = "";
//获取浏览器地址
const ipPort = document.location.protocol + "//" + document.location.host;
this.qrCodeImg = null;
this.qrCodeImg = new QRCode(this.$refs.qrCodeDiv, {
width: 150,
height: 150,
text: ipPort + '/details.html?id=' + this.id,
colorDark: "#000",
colorLight: "#fff",
correctLevel: QRCode.CorrectLevel.H
});
}
},
mounted () {
this.bindQRCode()
}