<div>
<div class="qrcode-pic" ref=codeitem style="margin-top: 15px;"></div>//生成二維碼顯示地方
<button @click='qrCode'>點擊生成二維碼</button>
</div>
js部分
data(){
return{
qrData:[{
url:"127........."
},{
url:"127........."
}]
}
}
qrCode(){
this.$nextTick(()=>{//必須寫在this.$nextTick否則會報錯.
this.qrData.forEach((item,index)=>{
let code = item.url;
this.$refs.codeitem.innerhtml="";
new QRCode(this.$refs.codeitem[index], {
text: code, //轉成二維碼的內容
width:150,
height: 150
})
})
})
}