xxx.vue

<template>
<a-modal
class="dialogRecharge"
title="活动链接及二维码"
v-model="visible"
width="520px"
:destroyOnClose="true"
:footer="null"
@cancel="$emit('close')"
>
<a-tabs type="card" v-model="tabKey" @change="getUrl">
<a-tab-pane tab="H5页面" key=""></a-tab-pane>
<a-tab-pane tab="微信小程序" key=""></a-tab-pane>
<a-tab-pane tab="抽奖大屏" key=""></a-tab-pane>
</a-tabs> <div class="codeBox">
<div class="img">
<qriously :id="'mycanvas' + tabKey" :value="dataObj.url" :size="" />
</div>
<a-button class="download" @click="downqriousl('mycanvas' + tabKey)">下载二维码</a-button>
<div class="copyLink">
<a-input-search v-model="dataObj.url" placeholder="51hejia.com....">
<a-button slot="enterButton">复制链接</a-button>
</a-input-search>
<div class="btn" @click="Clip($event, dataObj.url)"></div>
</div>
</div> </a-modal>
</template> <script>
import serviceMarketing from "@/service/marketing.js";
import Clipboard from 'clipboard';
export default {
data() {
return {
// visible: true,
visible: false,
itemData: {},
tabKey: '',
dataObj: {
url: ''
},
};
},
created() {
},
methods: {
Clip (event, text) {
let self = this
const clipboard = new Clipboard(event.target, {
text: () => text
});
clipboard.on('success', () => {
self.$message.success('复制成功')
clipboard.off('error');
clipboard.off('success');
clipboard.destroy();
});
clipboard.on('error', () => {
self.$message.error('复制失败,请刷新试试')
clipboard.off('error')
clipboard.off('success')
clipboard.destroy()
});
clipboard.onClick(event);
},
downqriousl(id){
console.log(id)
const type = 'png'
let canvas = document.getElementById(id).querySelector('canvas');
let imgdata=canvas.toDataURL(type);
//将mime-type改为image/octet-stream,强制让浏览器下载
let fixtype=function(type){
type=type.toLocaleLowerCase().replace(/jpg/i,'jpeg');
let r=type.match(/png|jpeg|bmp|gif/)[];
return 'image/'+r;
};
imgdata=imgdata.replace(fixtype(type),'image/octet-stream');
//将图片保存到本地
let savaFile=function(data,filename)
{
let save_link=document.createElementNS('http://www.w3.org/1999/xhtml', 'a');
save_link.href=data;
save_link.download=filename;
let event=document.createEvent('MouseEvents');
event.initMouseEvent('click',true,false,window,,,,,,false,false,false,false,,null);
save_link.dispatchEvent(event);
};
let filename=''+new Date().getSeconds()+'.'+type;
//用当前秒是解决重名的问题 不行就换成毫秒
savaFile(imgdata,filename);
},
getUrl () {
let self = this
self.$get(serviceMarketing.lotteryUrl.apiUrl, {
id: this.itemData.id,
type: this.tabKey
},(res => {
if(res.statusCode && res.statusCode == ""){
this.dataObj = res.data
} else {
self.$message.error(res.reason,);
}
}),serviceMarketing.lotteryUrl.domain);
},
modalOpen(itemData) {
console.log(itemData)
this.visible = true;
this.itemData = itemData
this.getUrl()
}
}
};
</script> <style lang="less" scoped>
.codeBox {
text-align: center;
.img{
width: 180px;
height: 180px;
margin: 35px auto 15px;
// border:1px solid red;
background: #f4f4f4;
border-radius: 5px;
canvas {
width: %;
height: %;
}
}
.download {
width: 180px;
margin-bottom: 10px;
}
.copyLink {
margin:35px 20px 15px;
position: relative;
.btn{
width: 90px;
position: absolute;
top: ;
right: ;
bottom: ;
z-index: ;
cursor: pointer;
}
}
}
</style>

https://www.cnblogs.com/ruthless/p/9970133.html

https://segmentfault.com/a/1190000014875645

.

vue-qriously 生成二维码并下载、cliploard复制粘贴的更多相关文章

  1. vue 中生成二维码之爬坑之路

    最近在做vue中项目,有个需求是在你提交信息后把后台返给你的链接生成二维码. 一共使用了两种生成二维码的方法 1.vue-qr 这个是在一进入页面直接生成二维码,具体介绍见文档:https://www ...

  2. Springboot生成二维码并下载图片png支持打包成zip

    pom.xml <!--二维码--> <dependency> <groupId>com.google.zxing</groupId> <arti ...

  3. 详细QRCode生成二维码和下载实现案例

    using System; using System.Collections.Generic; using System.Linq; using System.Web; using ThoughtWo ...

  4. Vue——前端生成二维码

    与后端生成二维码相比,前端生成二维码更具有灵活性,下面就介绍两种前端生成二维码的方式,两种方式相比之下,vue-qr比qrcode多了一个再中间添加logo的功能. 方式一:qrcode npm np ...

  5. vue中生成二维码

    <template> <div id="qrcode" ></div> </template> <script> imp ...

  6. iOS开发——高级技术&生成二维码

      生成二维码 因为项目里需要新增个功能,该功能用到了二维码技术.于是我便查阅了资料,先学习了二维码的生成. 我们使用libqrencode库来生成二维码.下载地址http://download.cs ...

  7. 链接生成二维码-PHP

    原文:http://www.upwqy.com/details/20.html 链接生成二维码 首先下载phpqrcode phpqrcode.zip 我这里使用的是TP5,把下载好的类库 放入到ex ...

  8. phporjquery生成二维码

    一.php生成二维码 下载文章末尾链接中phpcode文件 include "./phpqrcode/qrlib.php"; //QRcode::png('http://www.b ...

  9. vue2.0生成二维码图片并且下载图片到本地兼容写法

    vue生成二维码图片,这里使用的是qrcode.js 这个插件(亲测写法,兼容没有问题) 第一步,下载插件 需要注意,这里下载的是qrcodejs2 cnpm install --save qrcod ...

随机推荐

  1. ng add ng-zorro-antd 安装时报错 已经是管理员还需要权限Error: EPERM: operation not permitted, lstat 'C:\ngWorkspace\qd\node_modules\fsevents\node_modules'

    Error: EPERM: operation not permitted, lstat 'C:\ngWorkspace\qd\node_modules\fsevents\node_modules' ...

  2. Everything 配置问题导致信息泄露复现

    0x00 简介 Everything是一个私有的免费Windows桌面搜索引擎,可以在NTFS卷上快速地根据名称查找文件和目录. "Everything" 是 Windows 上一 ...

  3. 美好的童年伙伴:360 智能儿童手表 P1体验评测

    写在前面 少年儿童作为祖国的花朵,未来的栋梁,也是我们每个做家长的心头肉.近年来各种新闻报道中校园欺凌.虐待事件频发,虽然依然只是个别事件,但我们依然会心怀担忧. 360作为安防软件起家的专业公司,凭 ...

  4. 一加5安卓P刷入twrp的recovery

    本文介绍的方法属于普适性的一般方法,比网上的各种工具箱会繁琐.但是工具箱不一定一直会更新(之前一加论坛的刷机工具箱已经停止更新了,估计是作者不用一加5了吧,毕竟已经好几年的手机了).并且如果你手机更新 ...

  5. 对于模块加载:ES6、CommonJS、AMD、CMD的区别

    运行和编译的概念 编译包括编译和链接两步. 编译,把源代码翻译成机器能识别的代码或者某个中间状态的语言. 比如java只有JVM识别的字节码,C#中只有CLR能识别的MSIL.还简单的作一些比如检查有 ...

  6. C++指针的一些问题

    用变量a给出下面的定义: a)一个整形数(An integer) b)一个指向整形数的指针 c)一个指向指针的指针,它指向的指针指向一个整形数 d)一个有十个整形数的数组 e)一个有十个指针的数组,该 ...

  7. 01背包问题(dfs+剪枝)

    01背包问题 dfs解法 #include <iostream> #include <cstring> #include <algorithm> #include ...

  8. ARDUNIO IMU processing姿态数据可视化

    https://www.arduino.cn/thread-42852-1-1.html 关键数据打包 float roll, pitch, heading; Serial.print("O ...

  9. MySQL高级管理

    #mysql数据库密码的修改 一.mysql密码的修改与恢复 1.修改密码 mysqladmin -u root -p123 password 456 数据库内修改 method.first: upd ...

  10. LeetCode 988. Smallest String Starting From Leaf

    原题链接在这里:https://leetcode.com/problems/smallest-string-starting-from-leaf/ 题目: Given the root of a bi ...