vue3 使用 qrcodejs2 以及qrcodejs2-fix

在尝试使用npm安装qrcodejs2时遇到TypeError,读取未定义的_android属性。作者尝试了重装修复版本qrcodejs2-fix,并在Vue.js的组件中引入和设置二维码生成。在onMounted钩子函数中调用nextTick初始化二维码,但仍然遇到问题。
摘要由CSDN通过智能技术生成

注意:

// npm install qrcodejs2   
安装后报错:TypeError:Cannot read properties of undefined(reading‘_android‘)

没找到解决办法,重装了下面的



// npm install qrcodejs2-fix

使用

<template>
  <div class="qrCode" :id="el"></div>
</template>

<script setup>

// import QRCode from 'qrcodejs2-fix'

import QRCode from 'qrcodejs2-fix'
import { computed, onMounted, nextTick } from 'vue'

const props = defineProps({
  el: {
    type: String,
    required: true
  },
  options: {
    type: Object,
    required: false
  }
})
const currentEl = computed(() => props.el)
console.log(currentEl.value, 'currentEl')
onMounted(() => {
  nextTick(() => {
    autQRCode()
  })
})
const autQRCode = () => {
  let {
    text = '二维码',
    width = 200,
    height = 200,
    colorDark = '#333333',
    colorLight = '#ffffff',
    correctLevel = QRCode.CorrectLevel.L
  } = props.options
  const qrcode = new QRCode(currentEl.value, {
    text,
    width,
    height,
    colorDark, //二维码颜色
    colorLight, //二维码背景色
    correctLevel //容错率,L/M/H})
  })
  console.log(qrcode, 'qrcode')
  return qrcode.value
}
</script>
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值