How to get a local file using axios?

筅森魡賤 提交于 2020-08-07 08:05:31

问题


I am trying to get a local file:

Resultado.js:

componentWillMount(){
  axios.get('../config/db.json')
  .then(function(response){
    alert('ok');
  })
  .catch(function(error){
    alert('error');
  });
}

But, I am receiving an error:

Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null object reference

The file exists on the path

My file db.json:

[{"id":"87","codigo":"00504.050.000.00.00","nomeCadastro":"GOIVO DOBRADO"},{"id":"86","codigo":"02023.050.000.10.02","nomeCadastro":"GERB ONEDIN"},{"id":"85","codigo":"00212.070.999.00.00","nomeCadastro":"CRIS SANT REAN"},{"id":"84","codigo":"01297.019.000.00.00","nomeCadastro":"ANTH VARIADO"}]

回答1:


Just import data from json file and use it

    import data from '../config/db.json';

    render(){
     if(data){
      // do whatever you want with data here, 
     }
     ....
    }


来源:https://stackoverflow.com/questions/49235628/how-to-get-a-local-file-using-axios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!