Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get a local file using axios?

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

enter image description here

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"}]
like image 385
Italo Rodrigo Avatar asked Jan 29 '23 12:01

Italo Rodrigo


1 Answers

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, 
     }
     ....
    }
like image 93
tuan.tran Avatar answered Feb 12 '23 09:02

tuan.tran