行业知识
【Vue】后端返回文件流,前端预览文件
2026-11-13 21:07:43
来源:互联网转载
let date; request({ url: this.$route.query.url, method: 'get', responseType: 'blob', }).then(resp => { date = resp this.path = window.URL.createObjectURL(new Blob([resp], {type: "application/pdf"})) }).catch((e) => { //旧版本浏览器下的blob创建对象 window.BlobBuilder = window.BlobBuilder || window.WebKitBlobBuilder || window.MozBlobBuilder || window.MSBlobBuilder; if (e.name == 'TypeError' && window.BlobBuilder) { if (date) { BlobBuilder.append(date); this.path = URL.createObjectURL(new BlobBuilder().getBlob("application/pdf")) } } else { console.log("浏览器版本较低,暂不支持该文件类型预览"); } }).finally(() => { window.URL.revokeObjectURL(this.path); }) responseType必须设置为blob
index.php/tags-522.html" >文件预览效果
下一篇:移动服务器哪里有卖得?