qrcodejs2官网
// 安装
npm install --save qrcode
// 在需要的页面引用
import QRCode from "qrcodejs2";
// 使用
<template>
<view ref="qrCodeUrl"></view>
</template>
<script>
import QRCode from "qrcodejs2";
export default {
data() {
return {};
},
mounted() {
this.creatQrCode();
},
methods: {
creatQrCode() {
// 这样使用this.$refs.qrCodeUrl 是拿不到dom元素的
// 一定要 this.$refs.qrCodeUrl.$el
var qrcode = new QRCode(this.$refs.qrCodeUrl.$el, {
text: "https://www.baidu.com", // 需要转换为二维码的内容
width: 132,
height: 132,
colorDark: "#000000",
colorLight: "#ffffff",
correctLevel: QRCode.CorrectLevel.H,
});
},
this.$refs.qrcodeDiv.$el.innerHTML = '' // clear the code. 清除二维码
},
};
</script>