vue小工具之二维码生成(QRcode.js)

3 篇文章 0 订阅

vue小工具之二维码生成(QRcode.js)

Talk is cheap,Give you the code.
<template>
  <div class="qrCode">
    <div class="leftinput">
      <el-input
        type="textarea"
        v-model="text"
        maxlength="600"
        show-word-limit
        placeholder="请输入内容"
        @input="textChange"
      />
    </div>
    <div class="rightshow">
      <div class="qrcodeimg" v-if="img">
        <img :src="img" alt="" :style="imageStyle" />
        <p>用手机扫一扫,了解更多信息</p>
      </div>
    </div>
  </div>
</template>

<script>
import QRCode from 'qrcode';
export default {
  data() {
    return {
      text: '',
      img: '',
    };
  },
  computed: {
    imageStyle() {
      let h = 240;
      let w = 240;
      let l = this.text.length;
      h += l;
      w += l;
      if (h > 877) {
        h = w = 877;
      }
      return {
        height: `${h}px`,
        width: `${w}px`,
      };
    },
  },
  methods: {
    textChange() {
      QRCode.toDataURL(this.text)
        .then((url) => {
          this.img = url;
        })
        .catch((err) => {
          this.img = '';
          // this.$message.error(err);
        });
    },
  },
};
</script>

<style lang="scss" scoped>
* {
  margin: 0;
  padding: 0;
}
/deep/ .el-textarea {
  height: 100%;
  textarea {
    height: 100%;
    min-height: unset !important;
  }
}
.qrCode {
  display: flex;
  height: 100%;
  padding: 20px;
  .leftinput {
    width: 400px;
    background: #ffffff;
    border: 1px solid #d9d9d9;
    opacity: 1;
    border-radius: 3px;
    height: 100%;
  }
  .rightshow {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    .qrcodeimg {
      img {
        width: 240px;
        height: 240px;
        transition: all 300ms ease-in-out;
      }
      p {
        font-size: 18px;
        font-weight: 500;
        line-height: 32px;
        color: #334266;
        text-align: center;
      }
    }
  }
}
</style>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值