vue把后端返回的url转化成二维码
1.npm i qrcodejs2 --save
-
//所需页面导入
-
import QRCode from 'qrcodejs2'
完整代码
<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: 'https://blog.csdn.net/weixin_42601136', // 需要转换为二维码的内容(后端返回地址)
width: 100,
height: 100,
colorDark: '#000000',
colorLight: '#ffffff',
correctLevel: QRCode.CorrectLevel.H
})
},
},
mounted() {
this.creatQrCode();
},
};
</script>