安装
npm install --save qrcode
引入
import QRCode from 'qrcode'
使用
let opts = {
errorCorrectionLevel: "H",//容错级别
type: "image/png",//生成的二维码类型
quality: 0.3,//二维码质量
margin: 5,//二维码留白边距
width: 200,//宽
height: 180,//高
text: "http://www.xxx.com",//二维码内容
color: {
dark: "#333333",//前景色
light: "#fff"//背景色
}
};
let QRCodeMsg = window.location.href; //生成的二维码为URL地址js
let msg = this.$refs.share
// 将获取到的数据(val)画到msg(canvas)上
QRCode.toCanvas(msg, QRCodeMsg, opts, function (error) {
// conso.log(error)
console.log(error)
});