首页 > 其他分享 >vue3中使用qrcode生成二维码

vue3中使用qrcode生成二维码

时间:2023-11-09 14:38:11浏览次数:38  
标签:vue const aDom 组件 二维码 vue3 qrcode

安装

npm install --save qrcode.vue 
or 
yarn add qrcode.vue

组件中使用

<script setup lang="ts">
import { useUiSetStore } from '@store/modules/uiSettings'
//导入二维码组件
import QrcodeVue from 'qrcode.vue'
const ui = useUiSetStore()
const payUrl = ref('')
</script>

<template>
  <footer-modal :visible="ui.fToolsQR">
    <div>
        <input v-model="payUrl" type="text" class="w-150" placeholder="输入要生成的数据" />
      </div>
      <div class="m-auto my-2 w-14"></div>
      <div class="m-auto my-2 w-14">二维码</div>
      <div v-if="payUrl === ''" class="m-a h-50 w-50"></div>
      <div v-else class="m-a h-50 w-50">
          //组件中使用
          <qrcode-vue :value="payUrl" :size="200" level="H" />
    </div>
  </footer-modal>
</template>

全局注册使用

//main.ts中注册全局组件
import QrCode from './components/QrCode.vue'
const app = createApp(App)
app.component('qr-code',QrCode)

//组件中使用
<qr-code :value="links" :size="150" id="canvasDom"></qr-code>

下载qrcode二维码

const downLoadQRcode = ():void => {
    const canvas = document.getElementById('canvasDom') as HTMLCanvasElement
    const url = canvas.toDataURL("image/png") // 通过 toDataURL 返回一个包含图片展示的 data URI 
    const aDom = document.createElement("a")
    aDom.download = state.linksName// 设置下载的文件名
    aDom.href = url
    document.body.appendChild(aDom)
    aDom.click()
    aDom.remove()
}

标签:vue,const,aDom,组件,二维码,vue3,qrcode
From: https://blog.51cto.com/u_12828212/8278543

相关文章

  • vue2,vue3的优缺点
    vue2:优点:vue2比较成熟,所以具有比较完善的第三方的插件和库的支持,和技术资源的支持和解决方案d的社区等缺点:对ts语法的支持有限vue2中difff算法遍历dom树的关系,优化程度较低vue3:优点:引入一些高级的api优化了diff算法,使得性能更好,包更小对ts的语法支持更好......
  • uni-app vue3 获取元素报错问题
    关于uniapp中vue3使用uni.createSelectorQuery()时的this指向及查询结果说明_前端_谁凉了时光旧了少年-华为云开发者联盟(csdn.net)......
  • vue3 使用elementUI饿了么el-table组件 动态循环自定义表头列数据
     在vue3上使用el-table组件自定义循环表头列;<el-table:data="list"v-loading="loading"border>      <!--@selection-change="handleSelectionChange"-->      <!--<el-table-columntype="selection"wi......
  • vue3异步组件
    父组件中,子组件的加载一般是按照先后顺序加载的,子组件加载后才会加载父组件。一个页面的子组件很多,由于会先加载子组件,那么父组件可能会出现比较长的白屏等待时间大型项目,可能需要拆分应用为更小的块,并仅在需要时再从服务器加载相关组件Vue提供defineAsyncComponent方法:import......
  • vue3异步组件
    父组件中,子组件的加载一般是按照先后顺序加载的,子组件加载后才会加载父组件。一个页面的子组件很多,由于会先加载子组件,那么父组件可能会出现比较长的白屏等待时间大型项目,可能需要拆分应用为更小的块,并仅在需要时再从服务器加载相关组件Vue提供defineAsyncComponent方法:import......
  • vue3中使用Pinia
    Pinia是一个用于Vue的状态管理库,类似Vuex,是Vue的另一种状态管理方案三大核心:state(存储的值),getters(计算属性),actions也可支持同步(改变值的方法,支持同步和异步)npminstallpinia@nextoryarnaddpinia@next模块化封装创建实例新建store/index.ts(src目录下新建store......
  • 一个可以自动把微信的聊天收到的二维码图片实时提取出来并分类的软件
    10-1如果你有需要实时地、自动地把微信各个群收到的二维码图片提取出来的需求,那本文章适合你,本文章的主要内容是教你如何实现自动提取微信收到的二维码图片,助你快速扫码,永远比别人领先一步。 首先需要准备好的材料:1,一台电脑,个工具是电脑软件,手机不行2,你的微信,支持微信多开,多个也可......
  • Vue3 发送get 请求 携带数据
    exportfunctionTeam(data={}){returnservice.request({method:"get",url:"https://example.com/api/endpoint",//替换成实际的API端点params:{param1:data.param1,//根据传入的参数动态构建param2:data.param2}})......
  • uniApp:使用vue3+Vite4+pinia+sass技术栈构建(03)-封装对象类
    1.在src文件夹创建models文件夹import{user}from"@/service/api"//用户信息返回的数据类型interfaceuserInfoType{username:string,phone:string}//返回类型interfaceResultType<T>{errno:number,errmsg:string,datas:T}classuser......
  • vue3 axios 获得基地址
    1.位置 //axios基础的封装importaxiosfrom'axios'import'element-plus/es/components/message/style/css'import{ElMessage}from'element-plus'consthttpInstance=axios.create({baseURL:'http://laravel.cn',//基......