我使用 Axios.get 获取文件的路径:
C:\Users\me\AppData\Local\Temp\lorem.csv
axios语法获取
{
// axios post generate
const URL = '/api/report'+ '/generate'
axios.post(URL, {
report: this.editedItem.report,
values: this.editedItem.values
})
.then(response => {
this.fetchItem()
const URL = '/api/report/path'
axios.get(URL)
.then(response => {
this.path = response.data
})
.catch(err => {
alert(err)
})
})
.catch(err => {
//what happen after error
alert(err)
})
this.close()
}
我将该路径发送到 a 标记
<a :href="path" download target="_blank" class="tabs__item tabs__item--active" style="position: relative;"><u>{{ path }}</u></a>
but, console says : Not allowed to load local resource: [path]
我已经尝试过[不起作用]: - 节点: __dirname: false, __filename: false - blob类型数据 - 其他浏览器,还是一样
文件是动态的,服务器生成文件并将文件保存在目录中。
最佳答案
您使用 Axios 作为前端库,这意味着它无法访问文件系统。 不允许加载本地资源:
这告诉您正在尝试破坏浏览器中的沙箱。
Axios 专门用于调用 api,尽管您可以在 Node
之类的东西上使用它,这些东西确实可以通过诸如 fs
之类的东西访问文件系统,这就是为什么您仍然可以在浏览器中使用它时尝试执行此操作。
关于javascript - 不允许加载本地资源【Vue js with Axios】,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51176056/