1. 安装插件:
cnpm install qrcode2 --save
2. 在主页面引入并且使用:
<script>
import QRCode from 'qrcode2'
export default {
data () {
return {
url: ''
}
},
methods: {
getQrcode () {
Api.invite({page: 1}).then((res) => {
this.url = res.url
let qrcode = new QRCode(document.getElementById('qrcode'), {
text: res.url,
width: 160,
height: 160,
correctLevel: QRCode.CorrectLevel.H // 二维码容错级别 H M L
})
console.log(qrcode)
})
}
},
mounted () {
this.getQrcode()
}
}
</script>
<div id="qrcode" class="qrcode" src="111"></div>
.qrcode {
margin: 0.6rem;
-webkit-touch-callout: default;
img{
-webkit-touch-callout: default;
}
}
效果如下: