惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

WordPress大学
WordPress大学
The GitHub Blog
The GitHub Blog
F
Fortinet All Blogs
Cloudbric
Cloudbric
P
Palo Alto Networks Blog
T
Threatpost
T
Tor Project blog
T
Tenable Blog
AWS News Blog
AWS News Blog
Project Zero
Project Zero
L
LangChain Blog
Cyberwarzone
Cyberwarzone
Engineering at Meta
Engineering at Meta
雷峰网
雷峰网
C
CERT Recently Published Vulnerability Notes
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Security Latest
Security Latest
云风的 BLOG
云风的 BLOG
I
Intezer
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
P
Proofpoint News Feed
A
Arctic Wolf
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Google DeepMind News
Google DeepMind News
V
Vulnerabilities – Threatpost
C
Cybersecurity and Infrastructure Security Agency CISA
MongoDB | Blog
MongoDB | Blog
aimingoo的专栏
aimingoo的专栏
K
Kaspersky official blog
Jina AI
Jina AI
N
News | PayPal Newsroom
T
The Blog of Author Tim Ferriss
D
DataBreaches.Net
A
About on SuperTechFans
博客园 - 三生石上(FineUI控件)
博客园 - 【当耐特】
Hugging Face - Blog
Hugging Face - Blog
Recorded Future
Recorded Future
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
S
Secure Thoughts
TaoSecurity Blog
TaoSecurity Blog
P
Privacy & Cybersecurity Law Blog
P
Proofpoint News Feed
MyScale Blog
MyScale Blog
IT之家
IT之家
Forbes - Security
Forbes - Security
The Hacker News
The Hacker News
Last Week in AI
Last Week in AI
T
Threat Research - Cisco Blogs
Y
Y Combinator Blog

博客园 - ฅ˙-˙ฅ

用display实现效果:上面根据内容自适应高度;下面撑满所有,并且超出时候显示滚动条 react更改多层对象变量的方法 react umi model使用注意事项 拖动改变顺序 博文阅读密码验证 - 博客园 antd input控制只能输入数字并进行格式化显示(antd 3版本) react函数式组件:父组件调用子组件方法 react form表单中自定义组件的数据双向绑定实现 vue3+vant h5: Rem 移动端布局适配之postcss-pxtorem和lib-flexible 项目记录文档 前端mock方案:使用json-server mac安装使用nginx 博文阅读密码验证 - 博客园 umi修改antd主题颜色(通过less文件修改) 部署一个vue项目到阿里云服务器 vue重新刷新当前路由(非浏览器强刷,不会出现闪屏) 使用Vue.extend实现iview Upload在单文件上传时,拖拽多个文件给出错误提示 uni-app怎么使用路由守卫,并且路由配置和pages.json中只写一套 uni-app小程序iPhone X适配底部栏黑横线 使用css自定义变量实现实现主题切换功能
vue项目通过点击按钮实现复制图片(非图片url和base64),可发送到聊天框
ฅ˙-˙ฅ · 2021-01-16 · via 博客园 - ฅ˙-˙ฅ

1. 需求

通过接口拿到一个url,前端根据此url生成一个二维码并展示此二维码以及二维码说明文字,如图:

点击复制按钮,将红色框部分当做图片进行复制,并可通过聊天框(比如微信,qq)直接以图片形式发给客户

2. 实现

.vue文件如下:

<template>
    <div>
      <div id="QR-code">
        <div id="QR-img"></div>
        <div>二维码说明文字</div>
      </div>
      <Button @click="copyImg">点击复制图片</Button>
    </div>
</template>

<script>
import QRCode from 'qrcodejs2';
import html2canvas from 'html2canvas';

export default {
  data() {
    return {
      qr: null,
      imgUrl: '',
    };
  },
  methods: {
    createQR(url) {
      this.qr.makeCode(url);
    },
    copyImg() {
      html2canvas(document.getElementById('QR-code')).then(async (canvas) => {
        this.imgUrl = canvas.toDataURL();
        const data = await fetch(this.imgUrl);
        const blob = await data.blob();

        await navigator.clipboard.write([
          // eslint-disable-next-line no-undef
          new ClipboardItem({
            [blob.type]: blob,
          }),
        ]);
      });
    },
  },
  mounted() {
    // 生成包含地址信息的二维码
    this.qr = new QRCode(document.getElementById('QR-img'), {
      width: 260,
      height: 260, // 高度
    });
    this.createQR('https://www.baidu.com/');
  },
};
</script>

<style lang="less" scoped>
#QR-code {
    #QR-img {
      width: 260px;
      height: 260px;
    }
}
</style>

3. 说明

此方法目前只测试了chrome浏览器,有效。其他浏览器未进行测试
相关连接:
https://developer.mozilla.org/en-US/docs/Web/API/ClipboardItem/ClipboardItem
https://segmentfault.com/q/1010000024561218/a-1020000037738818 (此方法并没尝试成功,却给了很大提示)