vue下载静态的模板

news/2024/7/24 7:39:35 标签: vue

在组件文件中代码

export function downloadByA({ url, name = 'temp' }) {
  // 生成一个a元素
  const a = document.createElement('a')
  // 创建一个单击事件
  const event = new MouseEvent('click')
  // 设置图片名称
  a.download = name
  // 如果跳转页面,则在其他页面跳转
  a.target = '_blank'
  // 将生成的URL设置为a.href属性
  a.href = url
  // 触发a的单击事件
  a.dispatchEvent(event)
}

文件放在public/doc文件夹中

<el-link type="primary" @click="download">下载文件模板</el-link>
    download() {
      downloadByA({
        url: './doc/associatedOrderTemplate.xlsx',
        name: '模板.xlsx'
      })
    }

http://www.niftyadmin.cn/n/1367721.html

相关文章

element UI中table组件不换行

.el-table .cell {white-space: nowrap;}

身份证保留前6位和后两位其它用*号代替

idNum.replace(/(\w{6})\w*(\w{2})/, $1**********$2)示例

elemet ui 时间区间不可超过1年

<el-form-item prop"dateArea" label"交易时间&#xff1a;"><el-date-pickertype"date"placeholder"选择开始日期"v-model"ruleForm.dateArea1"></el-date-picker><span style"margin: 0 5px;&q…

Vue全家桶构建项目

步骤一、安装vue-cli 首先&#xff0c;我们可以通过npm安装vue-clic,前提是我们需要有node环境&#xff0c;如果电脑还没安装node&#xff0c;先安装&#xff0c;可通过 node -v 查询node的版本号&#xff0c;有版本号则已经安装成功&#xff1b; vue全家桶项目构建教程 接下…

Vue下载文件不成功及下载文件名称问题

看代码 import axiosDown from "axios";downloadFile(path) {return axiosDown({url: path,method: "get",responseType: "blob" // 这一步也很关键&#xff0c;一定要加上 responseType 值为 blob});},downloadWay(item) {// console.log(item…

js代码优化

1.避免多条件并列 let status process; let arr [process, wait, fail] if (arr.includes(status)) {console.log(避免多条件并列--2);}

C++ day44

1、全局变量&#xff0c;int monster 10000;定义英雄类hero&#xff0c;受保护的属性string name&#xff0c;int hp,int attcKk;公有的无参构造&#xff0c;有参构造&#xff0c;虚成员函数void AtK()[blood-0,}&#xff0c;法师类继承自英雄类&#xff0c;私有属性int ap_at…

JS大坑之17位(含)以后的Number类型数值精度丢失问题

1.JS大坑之17位&#xff08;含&#xff09;以后的Number类型数值精度丢失问题 console.log("1318855614830125158")console.log(Number("1318855614830125158"))console.log(parseInt("1318855614830125458"))console.log(String(13188556148301…