zoukankan      html  css  js  c++  java
  • js javascript 下载url为文件 下载项目里的文件

    下载项目里的文件

    // F:\projectCode\xxx-client\src\excel\pointTmt.xlsx
    
    import eventTemplate from '@/excel/pointTmt.xlsx'
    
    <a download="埋点文档格式规范.xlsx" :href="eventTemplate"> 埋点文档格式规范 </a>

    下载url为文件

    // const URL = window.URL || window.webkitURL || window.moxURL

    当参数不是blob时需要生成blob

    https://www.cnblogs.com/dhjy123/p/14988142.html

    // const blob = new Blob([res])
    function openDownloadDialog (url, saveName) {
        if (typeof url === 'object' && url instanceof Blob) {
          url = URL.createObjectURL(url)
        }
        var aLink = document.createElement('a')
        aLink.href = url
        aLink.download = saveName || ''
        var event
        if (window.MouseEvent) event = new MouseEvent('click')
        else {
          event = document.createEvent('MouseEvents')
          event.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null)
        }
        aLink.dispatchEvent(event)
      }
    
      openDownloadDialog(sheet2blob(sheet), xmlName + '.xlsx')

     2、

    const retData = await this.$api.userGroup.getOssFile(data.url)
      this.handleSaveAs(retData, record.title, record.id)
    
    
        handleSaveAs(blob, filename, id) {
          if (window.navigator.msSaveOrOpenBlob) {
            navigator.msSaveBlob(blob, filename)
          } else {
            const link = document.createElement('a')
            const body = document.querySelector('body')
            link.href = window.URL.createObjectURL(blob)
            link.download = filename
            // fix Firefox
            link.style.display = 'none'
            body.appendChild(link)
            link.click()
            body.removeChild(link)
            window.URL.revokeObjectURL(link.href)
          }
        }
  • 相关阅读:
    debian7.2+nginx+mysql
    VirtualBox为虚拟OS硬盘扩容
    VirtualBox-Debian7.2-share
    linux 标准化
    linux user date
    Array方法总结
    GET和POST区别 / doGet()和doPost()的区别
    servlet错误:HTTP Status 405
    python类型转换、数值操作
    Architecture:话说科学家/工程师/设计师/商人
  • 原文地址:https://www.cnblogs.com/dhjy123/p/15471012.html
Copyright © 2011-2022 走看看