elementui组件el-dialog踩坑

如图,我要实现这样的一个功能每次点击预览都会在弹出框生成一个二维码

完整的实现思路vue
html

  <el-dialog
          title="预览"
          :visible.sync="previewpic"
          v-show="previewpic"
          width="30%"
          style="height: 330px;z-index: 20000"
          class="preqrcode"
        >
          <div slot="footer" class="dialog-footer">
            <div class="qrcode" id="qrcode" ref="qrCodeUrl" style="height: 100px;width: 100px"></div>
            <el-button @click="previewpic = false">取 消</el-button>
            <el-button type="primary" @click="previewpic = false">确 定</el-button>
          </div>
        </el-dialog>

模板数据

data(){
    return {
        previewpic: false//控制dialog框的现实和隐藏
    }
}

js

//触发预览
 handlepreview() {
        //0是编辑,1是复制,没有是新建
        this.previewpic = true
        this.$refs.qrCodeUrl.innerHTML = ''
        var that = this
        if(this.$route.query.iscopy==="0"||this.$route.query.iscopy==="1"){
          //编辑的话直接看
            var qrCode = new QRCode(qrcode, {
              text: `https://sns.91fyt.com/h5/#/pages/ads/ads/?id=${that.$route.query.id}`,
              width: 100,
              height: 100,
              colorDark: '#000000',
              colorLight: '#ffffff',
              correctLevel: QRCode.CorrectLevel.H
            })
}

//注意点
1.
图片说明
2.qrCode的回调函数this指向函数里面,所以this不能写错
3.每次点击都要清空二维码,否则每次都会渲染一个新的二维码
方法是 this.$refs.qrCodeUrl.innerHTML = ''

全部评论

相关推荐

12-27 22:49
门头沟学院 Java
点赞 评论 收藏
分享
11-11 16:40
已编辑
门头沟学院 人工智能
不知道怎么取名字_:这个有点不合理了,相当于已经毕业了,但还是没转正,这不就是白嫖
点赞 评论 收藏
分享
回家当保安:复旦✌🏻,佬你的简历感觉挺好的,寒假日常hc比较少。佬可以过完年之后再试试,日常实习hc比较充足
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务