vue 下载pdf以及其他文件方法

1.

var data = 'http://218.94.150.147:8082/xhnmes/App_webs/Core/Programs/DOC/cpm.pdf'

fetch(data).then(res => res.blob().then(blob => {

           let a = document.createElement('a');

           let url = window.URL.createObjectURL(blob);

           a.href = url;

           a.download = 'CPM操作手册';

           a.click();

           window.URL.revokeObjectURL(url);

     }))

2.

var fileUrl = 'http://218.94.150.147:8082/xhnmes/App_webs/Core/Programs/DOC/CPM操作手册.docx'

 const replacedUrl = fileUrl.replace(/^http:/, 'http:')

 const ele = document.createElement('a')

 ele.setAttribute('href', replacedUrl)

 ele.setAttribute('download', replacedUrl.split('/')[replacedUrl.split('/').length - 1])

 ele.click()

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