vue動態生成批量二維碼生成

<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
            })
      })
  })
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章