vue中修改下载文件的名字,例如docx,pdf,xlsx

1.直接在拿到图片后直接写入以下代码 

        const blob = new Blob([this.detailinfo.reg_file_url], {//this.detailinfo是后台返回给前台的文档下载链接
           type: "application/msword",
         });
         const objectUrl = URL.createObjectURL(blob);
         const link = document.createElement("a"); //我们用模拟q标签点击事件
         const fname = name + this.detailinfo.title; //下载文件的名字
         link.href = objectUrl;
         link.setAttribute("download", fname);
         document.body.appendChild(link);
         link.click(); //点击
         document.body.removeChild(link); // 下载完成移除元素
         window.URL.revokeObjectURL(URL); // 释放掉blob对象
//针对移动端对于blob兼容不友好,华为手机无反应另外解决  pc端一切正常

猜你喜欢

转载自blog.csdn.net/wei80231996/article/details/114268722