vue中使用qrcodejs2生成二维码

npm地址 https://www.npmjs.com/package/qrcodejs2

安装

npm install qrcodejs2 --save 

官方给的文档非常简洁,所以用起来很简单

看单文件中的写法,基本一致。

<template>
  <div>
    <div id="qrcodeImg"></div>
    <!-- 创建一个div,并设置id -->
  </div>
</template>
<script>
import QRCode from 'qrcodejs2'; // 引入qrcode
export default {
  name: 'qrcode-img',
  components: {},
  props: {
    qrcontent: {
      type: String
    },
    width: {
      type: String
    },
    height: {
      type: String
    }
  },
  data() {
    return {};
  },
  mounted() {
    this.qrcode();
  },
  methods: {
    qrcode() {
      new QRCode('qrcodeImg', {
        width: this.width,
        height: this.height,
        text: this.qrcontent, // 二维码地址
        colorDark: '#000',
        colorLight: '#fff'
      });
     // 下边css自定义就行了。。。我这主要因为别的原因才改动的
    }
  }
};
</script>

<style lang="scss" scoped>
#qrcodeImg {
  box-sizing: border-box;
  display: inline-block;
  padding: 8px;
  background: #cccccc;
  & > img {
    display: inline-block !important;
  }
}
</style>

搞定!完结

  • 16
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 13
    评论
评论 13
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值