1.先下载
npm install qrcode --save-dev
2.引入
import QRCode from "qrcode";
3.生成二维码
<template>
<canvas id="QRCode_header"></canvas>
</template>
<script>
import QRCode from "qrcode";
export default {
data(){
return{
this.QRCodeMsg:""
}
}
getQRCode() {
let opts = {
errorCorrectionLevel: "H",
type: "image/png",
quality: 0.3,
margin: 12,
width: 200,
height: 180,
text: "http://www.xxx.com",
color: {
dark: "#333333",
light: "#fff"
}
};
this.QRCodeMsg = "http://www.baidu.com";
let msg = document.getElementById("QRCode_header");
QRCode.toCanvas(msg, this.QRCodeMsg, opts, function (error) {
conso.log(error)
});
},
}
</script>
api
width |
图像宽度 |
height |
图像高度 |
colorDark |
前景色 |
colorLight |
背景色 |
correctLevel |
QRCode.CorrectLevel.L 容错级别,可设置为: |
|
QRCode.CorrectLevel.L |
|
QRCode.CorrectLevel.M |
|
QRCode.CorrectLevel.Q |
|
QRCode.CorrectLevel.H |
参考链接
vue-qr