zoukankan      html  css  js  c++  java
  • js点击保存图片

     
    方法一:
     <img :src="codeIMG" alt="二维码图片" style="60%;" />
        <span @click="downloadCodeImg()">点击保存</span>
       
    codeIMG: require("../../assets/image/222.png")
     
    downloadCodeImg() {
          console.log("下载图片");
          var a = document.createElement("a");
          a.download = name || "pic"; // 设置图片地址
          a.href = this.codeIMG;
          a.click();
        },
     
     
     
    方法二:
     
      <img src="../../assets/image/business.png" alt="" ref="picurl" id="picurl"/>

        <a href="#" @click="savePic">保存到相册</a>
     
     
     
        savePic() {
          var picurl = this.$refs.picurl.src;

          //alert(picurl);
          this.savePicture(picurl);
        },
        savePicture(Url) {
          console.log(Url);
          var blob = new Blob([""], { type: "application/octet-stream" });
          var url = URL.createObjectURL(blob);

          var a = document.createElement("a");

          a.href = Url;

          a.download = Url.replace(/(.*/)*([^.]+.*)/gi, "$2").split("?")[0];
          console.log(a);
          var e = document.createEvent("MouseEvents");

          e.initMouseEvent(
            "click",
            true,
            false,
            window,
            0,
            0,
            0,
            0,
            0,
            false,
            false,
            false,
            false,
            0,
            null
          );
          a.dispatchEvent(e);
          console.log(URL.revokeObjectURL(url));
          URL.revokeObjectURL(url);
        },
  • 相关阅读:
    解决docker 容器删除不掉的问题
    centos下安装docker
    Microsoft SQL Server 双机热备份,实时同步
    同一台主机下的两台虚拟机互ping不通
    JAVA基本数据类型
    记录一些比较高能的网站!
    Nginx+Lua+Redis配置
    用Squid3搭建缓存代理服务器
    Mysql导入CSV文件
    LeetCode--Remove Duplicates from Sorted Array
  • 原文地址:https://www.cnblogs.com/1609359841qq/p/13092041.html
Copyright © 2011-2022 走看看