前端自动生成二维码并长按识别跳转 Vue

  1. 下载arale-qrcode依赖:
npm i arale-qrcode --save
  1. 引用依赖:
import AraleQRCode from "arale-qrcode";
  1. 代码部分:
<template>
  <div class="container">
    // 生成二维码按钮
	<van-button @click="getErweima">点击生成二维码</van-button>
	// 生成二维码弹窗
    <van-overlay :show="show">  
      <div class="wrapper">
          <img :src="img" />
      </div>
    </van-overlay>
  </div>
</template>

<script>
import AraleQRCode from "arale-qrcode";  //引入依赖
export default {
     
  name: "index",
  data() {
     
    return {
     
      show: false,
      img: "",
    };
  },
  mounted() {
     
  },
  methods: {
     
    makeCode() {
     
      const result = new AraleQRCode({
     
        render: "svg",
        text: "http://www.baidu.com",
        size: 120,
      });
      // 将svg xml文档转换成字符串
      const svgXml = new XMLSerializer().serializeToString(result);
      // 将svg字符串转成base64格式,通过 window.btoa方法创建一个 base-64 编码的字符串,进行二次编码解码(encodeURIComponent 字符串进行编码和解码,unescape 进行解码)。
      const src = "data:image/svg+xml;base64," + window.btoa(unescape(encodeURIComponent(svgXml)));
      localStorage.setItem("image", src);
      this.getImg();
    },

    // 获取存储的图片给到页面
    getImg() {
     
      this.img = localStorage.getItem("image");
      localStorage.removeItem("image");
    },
    getErweima() {
     
      this.show = true
      this.makeCode()
    },
  },
};
</script>
<style lang="scss" scoped></style>

Learning is like the fennel, but without its increase, it has its own advantages.

相关推荐

  1. 前端自动生成识别 Vue

    2024-02-23 12:52:03       50 阅读
  2. uniapp——识别

    2024-02-23 12:52:03       39 阅读
  3. 前端vue2生成可保存

    2024-02-23 12:52:03       56 阅读
  4. uniapp图片识别

    2024-02-23 12:52:03       65 阅读
  5. uniapp小程序——识别

    2024-02-23 12:52:03       35 阅读
  6. vue+vue-qr生成带logo的自动下载

    2024-02-23 12:52:03       35 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-02-23 12:52:03       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-02-23 12:52:03       106 阅读
  3. 在Django里面运行非项目文件

    2024-02-23 12:52:03       87 阅读
  4. Python语言-面向对象

    2024-02-23 12:52:03       96 阅读

热门阅读

  1. 基于开源模型对文本和音频进行情感分析

    2024-02-23 12:52:03       60 阅读
  2. 介绍C#和C#代码

    2024-02-23 12:52:03       52 阅读
  3. 【Antd】Form 表单获取不到 Input 的值

    2024-02-23 12:52:03       51 阅读
  4. Linux下各种压缩包的压缩与解压

    2024-02-23 12:52:03       44 阅读
  5. 【springBoot】统一功能处理

    2024-02-23 12:52:03       47 阅读
  6. TensorFlow基础

    2024-02-23 12:52:03       54 阅读