简体   繁体   English

不允许加载本地资源[带有Axios的Vue js]

[英]Not allowed to load local resource [Vue js with Axios]

I get the path of the file using Axios.get : C:\\Users\\me\\AppData\\Local\\Temp\\lorem.csv 我使用Axios.get获取文件的路径: C:\\Users\\me\\AppData\\Local\\Temp\\lorem.csv

Axios syntax get 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()
  }

And I send that path to the a tag 然后将该路径发送到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] 但是,控制台说:不允许加载本地资源:[路径]

I've tried [doesn't work]: - node: __dirname: false, __filename: false - blob type data - other browser, still same 我尝试过[不起作用]:-节点:__dirname:false,__filename:false-Blob类型数据-其他浏览器,仍然相同

The file is dynamic, server produce the file and save the file in the directory. 该文件是动态的,服务器生成该文件并将其保存在目录中。

You're using Axios as a frontend library, which means that it doesn't get access to the file system. 您将Axios用作前端库,这意味着它无法访问文件系统。 Not allowed to load local resource: This is telling you that you're trying to break the sandbox that is in the browser. Not allowed to load local resource:这是在告诉您您正在尝试破坏浏览器中的沙箱。

Axios is specfically for calling api's though you can use it on things like Node that do have access to the file system with something like fs which is why you can still attempt to do this when using it in the browser. Axios专门用于调用api,尽管您可以在诸如Node类的可以使用fs类的文件系统访问的东西上使用它,这就是为什么您仍可以在浏览器中尝试使用它的原因。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM