附件展示 点击下载

效果图 

附件展示 点击下载_第1张图片

 实现代码


            
          

    downContractFile(val) {
      request({
        url: "/appendix/downloadFile",
        method: "get",
        params: {
          appendixStorageName: val.appendixStorageName,
          appendixOriginalName: val.appendixOriginalName,
        },
        responseType: "blob",
      }).then((res) => {
        var filename = val.appendixOriginalName;
        var downloadElement = document.createElement("a");
        var href = window.URL.createObjectURL(new Blob([res])); //创建下载的链接
        downloadElement.href = href;
        downloadElement.setAttribute("download", filename);
        document.body.appendChild(downloadElement);
        downloadElement.click(); //点击下载
        document.body.removeChild(downloadElement); //下载完成移除元素
        window.URL.revokeObjectURL(href); //释放掉blob对象
      });
    },

你可能感兴趣的:(vue.js,javascript,elementui)