欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

vue使用qrcode生成二維碼的方法

 更新時間:2024年01月15日 09:22:17   作者:有蟬  
這篇文章給大家介紹了vue使用qrcode生成二維碼的方法,在Vue中實現(xiàn)二維碼生成需要使用第三方庫來處理生成二維碼的邏輯,常用的庫有qrcode和vue-qrcode,所以接下來小編將給大家介紹vue?qrcode生成二維碼的方法示例,需要的朋友可以參考下

一 安裝qrcode.js

npm install --save qrcode

二. 封裝生成二維碼的組件

index.vue

<template>
  <div class="QRCode" :style="{'width':width, 'height':height}">
    <canvas :id="canvasId" :style="{'width':width, 'height':height}"></canvas>
    <!-- <div class="QQMode" v-if="load || view"><a-icon type="download" @click="loadCode" v-if="load" /></div> -->
  </div>
</template>
<script>
import QRCode from "qrcode";
export default {
  name: "QRCode",
  props: {
    content: {
      type: String,
      default: "測試二維碼"
    },
    width: {
      type: String,
      default: "100"
    },
    height: {
      type: String,
      default: "100"
    },
    codeName: {
      type: String,
      default: "二維碼"
    },
    load: {
      type: Boolean,
      default: true
    },
    view: {
      type: Boolean,
      default: true
    }
  },
  data() {
    return {
      canvasId: ""
    };
  },
  computed: {},
  created() {
    this.canvasId = this.getUUID();
    this.$nextTick(() => {
      this.init();
    });
  },
  mounted: function() {},
  methods: {
    init() {
      let width = this.width,
        height = this.height;
      QRCode.toCanvas(
        document.getElementById(this.canvasId),
        this.content,
        { width, height, toSJISFunc: QRCode.toSJIS },
        error => {}
      );
    },
    getUUID() {
      let d = new Date().getTime();
      let uuid = "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(
        /[xy]/g,
        function(c) {
          let r = (d + Math.random() * 16) % 16 | 0;
          d = Math.floor(d / 16);
          return (c == "x" ? r : (r & 0x7) | 0x8).toString(16);
        }
      );
      return uuid;
    }
    //下載二維碼
    // loadCode() {
    //   let [F, S, a] = [
    //     navigator.userAgent.indexOf("Firefox") > -1,
    //     document.getElementById(this.canvasId).toDataURL("image/png"),
    //     document.createElement("a")
    //   ];
    //   // var dataurl = showel.toDataURL();
    //   var arr = S.split(","),
    //     mime = arr[0].match(/:(.*?);/)[1],
    //     bstr = atob(arr[1]),
    //     n = bstr.length,
    //     u8arr = new Uint8Array(n);
    //   while (n--) {
    //     u8arr[n] = bstr.charCodeAt(n);
    //   }
    //   var file = new File([u8arr], this.codeName + ".png", { type: mime });
    //   $A.FU(file, data => {
    //     // alert(1)
    //     // window.location.href = data;
    //     [a.href, a.download] = [data, this.codeName];
    //     // a.download = '二維碼';
    //     if (F) {
    //       let evt = document.createEvent("MouseEvents");
    //       evt.initEvent("click", true, true);
    //       a.dispatchEvent(evt);
    //     } else {
    //       a.click();
    //     }
    //   });
    // },
    // insertContentLoad(content, size) {
    //   const ele = document.createElement("canvas");
    //   ele.style.width = size.width || "100" + "px";
    //   ele.style.height = size.height || "100" + "px";
    //   QRCode.toCanvas(
    //     ele,
    //     content,
    //     {
    //       width: size.width || "100",
    //       height: size.height || "100",
    //       toSJISFunc: QRCode.toSJIS
    //     },
    //     error => {}
    //   );
    //   let [F, S, a] = [
    //     navigator.userAgent.indexOf("Firefox") > -1,
    //     ele.toDataURL("image/png"),
    //     document.createElement("a")
    //   ];
    //   [a.href, a.download] = [S, size.name];
    //   // a.download = '二維碼';
    //   if (F) {
    //     let evt = document.createEvent("MouseEvents");
    //     evt.initEvent("click", true, true);
    //     a.dispatchEvent(evt);
    //   } else {
    //     a.click();
    //   }
    // }
  },
  watch: {
    content(val) {
      this.init();
    }
  }
};
</script>
<style lang="scss" scoped>
.QRCode {
  display: inline-block;
  position: relative;
  overflow: hidden;
  .QQMode {
    position: absolute;
    left: 0;
    bottom: 100%;
    right: 0;
    height: 0;
    background-color: rgba(0, 0, 0, 0.45);
    transition: all 200ms ease-in-out;
    cursor: pointer;
    color: #fff;
    display: flex;
    justify-content: space-around;
    align-items: center;
    font-size: 20px;
    font-weight: bolder;
    box-sizing: border-box;
    padding: 10px;
  }
}
.QRCode:hover .QQMode {
  bottom: 0;
  height: 100%;
}
</style>

index.js

import index from './index.vue'
// This is the point
const QRcode = {
    install: function(Vue){
        Vue.component('QRcode',index);
    }
}
// Export components
export default QRcode

三. main.js引入

import QRcode from './components/QRcode'
Vue.use(QRcode);

四. 使用

<QRcode width="100" height="100" :content="content" :load="false"></QRcode>

content為在二維碼中存儲的信息,如下

let params = {
     userId: '123', //用戶id
     userName: 'Bob', //用戶名
     userNumber: 'sas123', //工號 
};
this.content = JSON.stringify(params);

以上就是vue使用qrcode生成二維碼的方法的詳細內(nèi)容,更多關(guān)于vue qrcode生成二維碼的資料請關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

  • vue2.0+koa2+mongodb實現(xiàn)注冊登錄

    vue2.0+koa2+mongodb實現(xiàn)注冊登錄

    這篇文章主要介紹了vue2.0+koa2+mongodb實現(xiàn)注冊登錄功能,非常不錯,具有參考借鑒價值,需要的朋友可以參考下
    2018-04-04
  • vue3如何監(jiān)聽頁面的滾動

    vue3如何監(jiān)聽頁面的滾動

    這篇文章主要給大家介紹了關(guān)于vue3如何監(jiān)聽頁面的滾動的相關(guān)資料,在vue中實現(xiàn)滾動監(jiān)聽和原生js無太大差異,文中通過圖文介紹的非常詳細,需要的朋友可以參考下
    2023-07-07
  • vue3響應式Proxy與Reflect的理解及基本使用實例詳解

    vue3響應式Proxy與Reflect的理解及基本使用實例詳解

    這篇文章主要為大家介紹了vue3響應式Proxy與Reflect的理解及基本使用實例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2022-08-08
  • vue實現(xiàn)跳轉(zhuǎn)接口push 轉(zhuǎn)場動畫示例

    vue實現(xiàn)跳轉(zhuǎn)接口push 轉(zhuǎn)場動畫示例

    今天小編就為大家分享一篇vue實現(xiàn)跳轉(zhuǎn)接口push 轉(zhuǎn)場動畫示例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2019-11-11
  • websocket在vue2中的封裝使用方式

    websocket在vue2中的封裝使用方式

    這篇文章主要介紹了websocket在vue2中的封裝使用方式,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2024-08-08
  • vue3+typescript實現(xiàn)圖片懶加載插件

    vue3+typescript實現(xiàn)圖片懶加載插件

    這篇文章主要介紹了vue3+typescript實現(xiàn)圖片懶加載插件,幫助大家更好的理解和使用vue,感興趣的朋友可以了解下
    2020-10-10
  • vue3父組件和子組件如何傳值實例詳解

    vue3父組件和子組件如何傳值實例詳解

    近期學習vue3的父子組件之間的傳值,發(fā)現(xiàn)跟vue2.x的父子組件之間的傳值并沒有太大的區(qū)別,下面這篇文章主要給大家介紹了關(guān)于vue3父組件和子組件如何傳值的相關(guān)資料,需要的朋友可以參考下
    2022-08-08
  • Vue整合AdminLTE模板的方法

    Vue整合AdminLTE模板的方法

    這篇文章主要介紹了Vue整合AdminLTE模板的方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-05-05
  • vue項目依賴升級報錯處理方式

    vue項目依賴升級報錯處理方式

    這篇文章主要介紹了vue項目依賴升級報錯處理方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-08-08
  • vue使用過濾器格式化日期

    vue使用過濾器格式化日期

    這篇文章主要為大家詳細介紹了vue使用過濾器格式化日期,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-01-01

最新評論