a标签下载文件 <a> 标签的 download 属性,window.location.href下载文件 新窗口打开 打开页面

本文介绍了如何利用HTML的a标签结合download属性以及window.open方法实现文件下载,包括在同一窗口替换内容下载和新窗口打开页面下载的实现方式。
摘要由CSDN通过智能技术生成

a标签啥都不做 

<a :href=" item.feedBackFile ?  baseUrl + item.feedBackFile : 'javascript:;'">
1、<a> 标签的 download 属性 下载文件
<a href="/images/myw3schoolimage.jpg" download="w3logo">
2、js方法 
window.location.href  -- (页面可能会出现移动,最好用a标签)
function openNewUrl(urlID){
 window.location.href = href +"/message/exportWord?id="+urlID;
};

window.open(url,"_self");

downLoad(row) {
      // console.log(row, "rowrowrowrowrow");
      let obj = this.arrData[row.rowIndex];
      let file = obj.feedBackFile;
      let url = process.env.VUE_APP_API_BASEURL + file;
      // let url = process.env.VUE_APP_API_BASEURL + "/profile/upload/2023/01/13/政治轮训反馈_20230113184125A001.xls";
      if (file) {
          window.open(url,"_self");
        // window.location.href = process.env.VUE_APP_API_BASEURL + "/profile/upload/2023/01/13/政治轮训反馈_20230113184125A001.xls";
      }
    },
    download() {
      if (!this.selectYear) {
        this.$message({
          message: "请选择下载数据类型",
          type: "warning",
          offset: 50
        });
      } else if (this.selectYear === "1") {
        let url1 = this.baseurl + `/newZj/message/exportWord?id=${this.id}`;
        this.axios.get(url1).then(res1 => {
          if (res1.data) {
            window.location.href = url1;
          } else {
            this.$message({
              message: "下载失败,没有相关数据",
              type: "warning",
              offset: 50
            }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值