vue js前端根据所需参数生成二维码并下载
生活随笔
收集整理的這篇文章主要介紹了
vue js前端根据所需参数生成二维码并下载
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
然后可以在需要下載生成二維碼的地方觸發(fā)這個事件
到此就完成了前端根據(jù)參數(shù)生成二維碼,并下載。
項目需求 使用element 表格 來動態(tài)生成二維碼,要求鼠標移入時顯示二維碼。
注意這里code 函數(shù)是放在 methods 里面的,不要試圖使用計算屬性來觸發(fā),有可能會重復渲染二維碼。
截出部分項目中代碼
<template v-if="item.prop === 'linkCodeUrl'" #default="{ $index }"><p class="p" @click="copy(data[$index])">復制鏈接</p><el-popover popper-class="cloud-qrcode" placement="right" width="200" trigger="hover"><div :id="`qrcode${$index}`"></div><spanslot="reference"class="p"@click="downloadCode(data[$index], $index)"@mouseover="code(data[$index].id, $index)">下載二維碼</span></el-popover></template>js部分
code(val, index) {console.log(index, 'pindex');this.$nextTick(() => {document.getElementById(`qrcode${index}`).innerHTML = '';const url = xxxxxx?id=${val}`;const qrcode = new QRCode(`qrcode${index}`, {width: 200,height: 200,text: url,background: '#f0f',foreground: '#ff0',});return qrcode;});},效果圖:
總結
以上是生活随笔為你收集整理的vue js前端根据所需参数生成二维码并下载的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: cf中的pve是什么意思 为什么还有人玩
- 下一篇: cf荣耀枪王和枪王有什么区别 为什么还有