• vue生成二维码:vueqr二维码插件使用


    生成的二维码中间可以放头像

    1、安装

    以管理员身份运行

    npm install vue-qr --save

    2、导入

    import VueQr from 'vue-qr'

    3、注册:

    components: { VueQr },

    4、使用

    点击按钮

    <el-button type="primary" size="mini" @click="handlePrint()">打印二维码</el-button>

    handlePrint方法如下:

    handlePrint() {
          this.$prompt('二维码数量', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            inputPattern: /^-?[1-9]\d*$/,
            inputErrorMessage: '必须为数字'
          }).then(({ value }) => {
            if (value > 200 && value != null) {
              this.$message.info('一次最多打印200个')
              return
            }
            this.qrcodeCount = []
            this.qrcodeCompleted = true
            this.innerVisible = true
            for (let i = 1; i <= parseInt(value); i++) {
              this.qrcodeCount.push({
                value: "https://www.baidu.com/"
              })
            }
          }).catch((error) => {
            console.log(error)
          })
        }

    展示二维码

    <el-dialog title="打印二维码" width="75%" :visible.sync="innerVisible">
          <div id="print" ref="print" v-loading="!qrcodeCompleted">
            <div v-for="(item, index) in qrcodeCount" style="display: inline-block;text-align: center;margin:10px 10px;">
              <vue-qr :logoSrc="logoSrc" :text="item.value" :size="120" :margin="0"></vue-qr>
            </div>
          </div>
          <el-button type="primary" v-print="'#print'">开始打印</el-button>
        </el-dialog>

    效果:

    点击按钮,弹出提示框

    点击确定,弹出对话框

    点击“打印二维码”按钮

    所有代码:

    <template>
      <div>
        <el-button type="primary" size="mini" @click="handlePrint()">打印二维码</el-button>
        <el-dialog title="打印二维码" width="75%" :visible.sync="innerVisible">
          <div id="print" ref="print" v-loading="!qrcodeCompleted">
            <div v-for="(item, index) in qrcodeCount" style="display: inline-block;text-align: center;margin:10px 10px;">
              <vue-qr :logoSrc="logoSrc" :text="item.value" :size="120" :margin="0"></vue-qr>
            </div>
          </div>
          <el-button type="primary" v-print="'#print'">打印二维码</el-button>
        </el-dialog>
      </div>
    </template>
    
    <script>
    import VueQr from 'vue-qr'
    export default {
      name: 'Index',
      components: { VueQr },
      created() {
      },
      mounted() {
      },
      data(){
        return{
          qrcodeCount: [],
          qrcodeCompleted: false,
          innerVisible: false,
          logoSrc: require('../assets/guaileen.png'),
        }
      },
      methods: {
        handlePrint() {
          this.$prompt('二维码数量', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            inputPattern: /^-?[1-9]\d*$/,
            inputErrorMessage: '必须为数字'
          }).then(({ value }) => {
            if (value > 200 && value != null) {
              this.$message.info('一次最多打印200个')
              return
            }
            this.qrcodeCount = []
            this.qrcodeCompleted = true
            this.innerVisible = true
            for (let i = 1; i <= parseInt(value); i++) {
              this.qrcodeCount.push({
                value: "https://www.baidu.com/"
              })
            }
          }).catch((error) => {
            console.log(error)
          })
        }
      }
    }
    </script>
  • 相关阅读:
    关于Java中System.currentTimeMillis和System.nanoTime的错误认识
    多线程以外
    vim 小技巧
    Virtual Box HostOnly网络模式配置
    How 30 Minutes a Day Can Increase Your Intelligence
    YUM命令使用
    Hash算法及其应用
    jetty + apache httpd 反向代理配置
    使用SCTP优化网络
    .NET书籍推荐
  • 原文地址:https://www.cnblogs.com/zwh0910/p/16111713.html
Copyright © 2020-2023  润新知