qrcodejs2报错,TypeError:Cannot read properties of undefined(reading‘_and'_android'

1,586 阅读1分钟

vue2的项目引入第三方插件qrcodejs2,绘制二维码本地没问题。 代码发到测试环境,构建后页面报错TypeError:Cannot read properties of undefined(reading‘_and'_android'

如下图: image.png

解决方法:引入qrcodejs2-fix

npm i --save qrcodejs2-fix

在页面中使用,引入依赖

import QRCode from 'qrcodejs2-fix'

写个方法,绘制二维码

createQrcode() {
  const codeUrl = 'http://www.baidu.com'
  new QRCode(this.$refs.qrcode, {
    width: 156, // 设置宽度
    height: 156, // 设置高度
    text: codeUrl
  })
},

生成二维码(打了马赛克)

image.png