javascript - 不允许加载本地资源【Vue js with Axios】

标签 javascript vuejs2 axios

我使用 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/

相关文章:

javascript - 需要帮助限制数组/优化 axios 响应

reactjs - 使用axios限速的建议

node.js - 如何在与 axios 的 react 中映射新帖子?

javascript - 选择数组中的所有值

javascript - 如何防止我的触摸设备执行::hover 而不是点击功能?

json - Vue 获取 response.json promise 不会创建响应式(Reactive) setter/getter

javascript - 如何将 vue 项目提供给网络上的其他计算机

javascript - 一个序列的 Python 'enumerate' 的 ES6 等价物是什么?

javascript - 在 vue 上关闭模态时如何运行语句?

javascript - 我可以检测所有图像何时加载,以便将 isLoaded 变量更改为 true 吗?