当前位置: 首页 > news >正文

vue使用qrcodejs2生成二维码

目录

概要

构建展示的vue组件qrcode.vue

组件的使用


概要

项目中用到需要展示二维码的样式,想到了qrcode

例如:

前提:安装包

npm install qrcodejs2 --save

构建展示的vue组件qrcode.vue

<template><div style="width: 100%;height: 100%;" :id="id" :ref="id"></div>
</template>
<script>
import QRCode from 'qrcodejs2'
export default {data() {return {qrcode: ''}},props: {id: {type: String,required: true},text: {  // 后端返回的二维码地址type: String,default: 'M000001'},width: {type: String,default: '100'},height: {type: String,default: '100'},colorDark: {type: String,default: '#000000'},colorLight: {type: String,default: '#ffffff'}},watch: {text(newText) {this.createQrcode()}},mounted() {this.createQrcode()},methods: {createQrcode() {if(this.qrcode) {  // 有新的二维码地址了,先把之前的清除掉this.$refs[this.id].innerHTML = ''}this.qrcode = new QRCode(this.$refs[this.id], {text: this.text, //页面地址 ,如果页面需要参数传递请注意哈希模式#width: this.width, // 二维码宽度 (不支持100%)height: this.height, // 二维码高度 (不支持100%)colorDark: this.colorDark,colorLight: this.colorLight,correctLevel: QRCode.CorrectLevel.H,})},// 制作另一个二维码updateCode() {this.qrcode.makeCode("http://naver.com")}}
}
</script>

组件的使用

<template><div>/***item为二维码的内容*colorDark为前景色*/<QrCode :id="'QrCode'" :text="item" colorDark="#802126"/></div></template>
<script>
import QrCode from '../../components/QRcode/qrCode.vue'  // 引用上面封装的二维码组件
export default {
components: { QrCode },//注册组件}</script>

小结

这个组件还是相当好用的,多多推荐

http://www.lryc.cn/news/147862.html

相关文章:

  • python注释
  • update-alternatives详解
  • JavaScript 编写更好的条件语句
  • 聊聊PBE算法
  • 用MFC打开外部程序
  • 基于全新电脑环境安装pytorch的GPU版本
  • [当前就业]2023年8月25日-计算机视觉就业现状分析
  • 虚拟化技术原理
  • opencv-答题卡识别判卷
  • 【Linux】基础IO
  • 【Go 基础篇】深入探索:Go语言中的二维数组
  • IntelliJ IDEA 2023.2.1使用Git时弹出“使用访问令牌登录”问题解决
  • 前端开发学习路线
  • 1、英飞凌-AURIX-TC297简介
  • Android 音频框架 基于android 12
  • 项目实践:类平面抓取点计算(占位,后面补充)
  • 中央空调秒变智能 青岛中弘P15面板式空调网关初体验
  • vue create -p dcloudio/uni-preset-vue my-project创建文件报错443
  • 本地电脑搭建Plex私人影音云盘教程,内网穿透实现远程访问
  • CI/CD 持续集成 持续交付
  • 《Go 语言第一课》课程学习笔记(十一)
  • C++--完全背包问题
  • 显示本地 IP 地址和相应的 QR 码,方便用户共享和访问网络信息
  • 为什么建议同时学多门编程语言
  • langchain agent
  • Zabbix下载安装及SNMP Get使用
  • freee Programming Contest 2023(AtCoder Beginner Contest 310)
  • 恒运资本:概念股是什么意思
  • 十九、状态模式
  • MySQL用navicat工具对表进行筛选查找