首页 > 其他分享 >vue使用vue-qr生成二维码

vue使用vue-qr生成二维码

时间:2023-04-25 19:56:02浏览次数:51  
标签:vue const text jumplink 二维码 qr

vue-qr基础使用:

第一步,先安装 vue-qr 插件

npm install vue-qr --save
第二步,在想要生成vueQr 的Vue页面引入组件

import vueQr from 'vue-qr'
第三步,在components中引入VueQr组件

components: { VueQr }
如下:

<script>
import VueQr from 'vue-qr';

export default {
    components: {
    VueQr,
    },
}
</script>

 

data() {
  return {
          logo:require("@/assets/images/1.jpg"),//默认二维码中间图片,图片需要使用require
          textUrl: "https://baidu.com" //二维码内容,我这里是扫码后要跳转的链接

}

},
// <template>
 //  <vue-qr :text="config.text" :logoScale="40" :size="300" :logoSrc="config.logo">
 //  </vue-qr>
// </template>

我这里二维码不需要中间logo

<vue-qr :text="qrUrl" :margin="0"></vue-qr>

参数说明:
1、:text 用于绑定生成二维码内容
2、:logoScale 中间logo标志大小,单位px
3、:logoSrc 用于绑定二维码中间logo图片的地址

 

vue-qr组件中的属性如下图:

 

我这里的业务场景是:在PC端扫描二维码跳转下载app

实现逻辑:

1.安装使用vueqr生成二维码插件,生成二维码, 扫二维码跳转到h5中转页面(先开发一个h5页面做为中转页面)

2.在pc端获取配置项得到安卓手机 苹果手机的下载地址 携带到中转页面

3.在中转页面判断是安卓手机还是ios打开 使用window.location.href分别跳转到不同的下载

PC端:
<template>
 <div class="item-qrcode"">
    <vue-qr :text="qrUrl" :margin="0"></vue-qr>
     <div class="title">下载APP</div>
  </div>
</template> <script> import VueQr from "vue-qr";  export default { name: "header-comp", components: { VueQr }, }, data() { return {// 下载APP中转页面传递的参数  jumpLink: {
//安卓下载链接 androidUrl: "https://baidu.com",
//ios下载链接 iosUrl: "https://www.jianshu.com/" } }; }, created() {
 // 二维码Url
this.qrUrl = `${window.envConfig.custom.qrcodePage}pages/template/download-app/pages/page?formItem=${JSON.stringify(this.jumpLink)}`; }, methods: {  }; </script> <style lang="scss" scoped> .download-app { width: 100%; text-align: center; .title, .text { font-size: 15px; color: #333333; } .title { font-weight: bold; } .text { text-indent: 2em; text-align: left; margin: 8px 0 10px 0; } .qrcode { display: flex; justify-content: space-evenly; .item-qrcode { text-align: center; .title { width: 85px; flex-wrap: warp; font-size: 14px; color: #333333; margin: 5px 0; } img { display: inline-block; width: 85px; height: 85px; margin: 0 auto; } } } } </style>
<template>
  <!-- PC端下载APP-h5中转页面 -->
  <view class="topnet-container">
  </view>
</template>
<script>
  export default {
    data() {
      return {
        jumplink: {},
      };
    },
    created() {
      this.getjumplink();
    },
    methods: {
      getjumplink() {
        const user = navigator.userAgent;
        // android端
        const isAndroid = user.indexOf('Android') > -1 || user.indexOf('Adr') > -1;
        // ios端
        const isiOS = !!user.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);
        // 接收参数
        const parameters = window.location.hash;
        if (parameters.indexOf('?') == -1) return null;
        const strs = parameters.substring(1).split('&');
        for (let i = 0; i < strs.length; i++) {
          const str = strs[i].split('=');
          this.jumplink = JSON.parse(decodeURIComponent(str[1]));
        }
        // 去掉链接两边双引号
        this.jumplink.androidUrl = this.jumplink.androidUrl.replace(/\"/g, '');
        this.jumplink.iosUrl = this.jumplink.iosUrl.replace(/\"/g, '');
        // 判断跳转
        if (isAndroid) {
          window.location.href = this.jumplink.androidUrl + '?time=' + new Date().getTime();
        } else if (isiOS) {
          window.location.href = this.jumplink.iosUrl + '?time=' + new Date().getTime();
        }
      },
    },
  };
</script>

<style lang="scss" scoped>
  .topnet-container-content {
    display: flex;
    flex-direction: column;
    align-items: center;
  }
</style>

 

 

require

标签:vue,const,text,jumplink,二维码,qr
From: https://www.cnblogs.com/angel648/p/17353662.html

相关文章

  • React和Vue的区别
    React和Vue是两个非常流行的JavaScript框架,用于构建前端Web应用程序。以下是它们之间的一些区别:模板语法:Vue使用模板语法,它允许您在HTML模板中嵌入Vue代码,类似于AngularJS。React使用JSX语法,它允许您将JavaScript代码嵌入HTML模板中。数据绑定:Vue使用双向数据绑定,这意味着当......
  • vue3+vite自适应PC端
    1、下载包pnpmaddlib-flexible-computerpostcss-px2rempx2rem-loader-D2、在main.ts里引入import"lib-flexible-computer";3、在vite.config.ts写入importpx2remfrom"postcss-px2rem"css:{postcss:{plugins:[px2rem({......
  • Vue3中slot插槽使用方式
    **********************************Vue3中slot插槽使用方式****************************************************参考:https://huaweicloud.csdn.net/638eab83dacf622b8df8d08c.html<templatev-slot:isFang></template>简写v-slot:isFang#isFang<template#isFan......
  • vue-element-admin报错Error: error:0308010C:digital envelope routines::unsupporte
    安装vue-element-admin报错 nodejs  Node.jsv18.15.0  opensslErrorStack:['error:03000086:digitalenveloperoutines::initializationerror'],library:'digitalenveloperoutines',reason:'unsupported',code:'ERR_OSSL......
  • D365: 生成Warehouse mobile app连接环境二维码
     //JSON文件格式{"ConnectionList":[{"ActiveDirectoryClientAppId":"206a394e-0dd6-44d5-a50b-796cef0d4bXX","ConnectionName":"Vyung-Test","ActiveDirectoryResource":"https://handvyung-test.......
  • 动力节点老杜Vue框架教程【二】Vue核心技术
    Vue.js是一个渐进式MVVM框架,目前被广泛使用,也成为前端中最火爆的框架Vue可以按照实际需要逐步进阶使用更多特性,也是前端的必备技能动力节点老杜的Vue2+3全家桶教程已经上线咯!学习地址:https://www.bilibili.com/video/BV17h41137i4/视频将从Vue2开始讲解,一步一个案例,知识点......
  • Vue3---error xx should be on a new line
    ESLint:':render-header'shouldbeonanewline.(vue/max-attributes-per-line)此问题是由于.eslintrc.js文件中的vue/max-attributes-per-line配置错误产生的"vue/max-attributes-per-line":['error',{"singleline":10,......
  • 老杜Vue实战教程完整版笔记(二)Vue核心技术
    动力节点老杜全新版Vue教程笔记分享给大家学习の地止:https://www.bilibili.com/video/BV17h41137i4视频教程从Vue2开始讲解,一步一个案例,知识点由浅入深,然后很自然的过度到Vue3版本。Vue3是目前企业中使用最多的一个版本。视频中会把每一个Vue的知识点讲解的非常通透,不但举例......
  • vite + vue3 + vue-router4 + ts + element plus + pinia + axios构建项目
    最后是完整的vite.config.ts、main.ts配置1、先用vite创建一个项目npmcreatevite@latest2、安装elementplusyarnaddelement-plus@element-plus/icons-vuevite.config.ts配置组件按需导入,图标自动导入npminstall-Dunplugin-vue-componentsunplugin-auto-impor......
  • 使用Vue实现点击事件变颜色并且显示选中文字
    首先需要引入Vue.js!!!!!   直接上代码<!DOCTYPEhtml><htmllang="en"><head><metacharset="UTF-8"><title>Title</title><scriptsrc="../static/vue.js"></script><st......