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. Github 上 10 个值得学习的 Springboot 开源项目

    Spring Boot 几乎继承了所有 Spring 框架的优点,同时还可以让项目的配置更简化.编码更简化.部署更方便.近两年受到很多开发者的追捧,也是火热的不行! 下面给大家整理了 10 个 Git ...

  2. MySQL/MariaDB数据库的冷备份和还原

    MySQL/MariaDB数据库的冷备份和还原 作者:尹正杰  版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.MySQL/MariaDB数据库的备份和还原概述 1>.为什么要备份 为了 ...

  3. 如何确定C++继承层次中的函数调用

    ```cpp //============================================================================ // Name : TS.c ...

  4. iptables 规则学习

    iptables 一共有 3 张表:mangle,nat,filter mangle 表主要处理 ttl,tos,mark 等信息(进) filter 顾名思义就是过滤器,用作防火墙(出) nat 主 ...

  5. object store in javascript

  6. 算法笔记求序列A每个元素左边比它小的数的个数(树状数组和离散化)

    #include <iostream> #include <algorithm> #include <cstring> using namespace std ; ...

  7. 了解一下Elasticsearch的基本概念

    一.前文介绍 Elasticsearch(简称ES)是一个基于Apache Lucene(TM)的开源搜索引擎,无论在开源还是专有领域,Lucene 可以被认为是迄今为止最先进.性能最好的.功能最全的 ...

  8. Tcl数学运算

    expr 数学表达式 Tcl支持的数学操作符(优先级按照从高到低): -一元负号 +一元正号 ~按位取反 !逻辑非 *乘 /除 %取余 +加号 -减号 <<左移位 >>右移位 ...

  9. cpu指令重排序的原理

    目录: 1.重排序场景 2.追根溯源 3.缓存一致性协议 4.重排序原因 一.重排序场景 class ResortDemo { int a = 0; boolean flag = false; pub ...

  10. NIO Channel Scatter/Gather 管道Pipe类

    通道提供了一种被称为Scatter/Gather的重要新功能(有时也被称为矢量I/O).Scatter/Gather是一个简单却强大的概念,它是指在多个缓冲区上实现一个简单的I/O操作.对于一个wri ...