zoukankan      html  css  js  c++  java
  • a标签下载图片及js执行下载图片

    a标签下载图片及js执行下载图片

     一般HTML中下载

    <div>
        <img id="img" src="./logo.png" alt="">
        <div><a href="./logo.png" download="fei_01.png">download_01</a></div>
        <div><button onclick="foo()">download_02</button></div>
    </div>
    
    <script>
        function foo() {
            const a = document.createElement('a')
            a.download = 'fei_02.png'; // 下载名字
            a.href = './logo.png' // 图片地址(tip:不要带https http)
            a.click();
            a.remove()
        }
    </script>

     Vue 中下载图片demo

    <template>
      <div class="block">
        <span>下载图片</span>
        <p><img :src="img" alt="图片"></p>
        <p><a :href="img" download>直接下载</a></p>
        <button @click="downloadImg">下载图片</button>
      </div>
    </template>
    <script>
    import img from "@/assets/logo.png"
    
    export default {
      data() {
        return {
          img
        }
      },
      methods: {
        downloadImg() {
          const a = document.createElement('a')
          a.download = '图片名字.png';
          a.href = img
          a.click();
          a.remove()
        }
      },
    };
    </script>
  • 相关阅读:
    Stack的一种简单实现
    Allocator中uninitialized_fill等函数的简单实现
    Allocator的简易实现
    编写自己的迭代器
    简单的内存分配器
    vector的简单实现
    异常类Exception
    intent大致使用
    java初识集合(list,set,map)
    php分页
  • 原文地址:https://www.cnblogs.com/dafei4/p/15622829.html
Copyright © 2011-2022 走看看