如何使用 axios 获取本地文件? [英] How to get a local file using axios?
本文介绍了如何使用 axios 获取本地文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试获取本地文件:
I am trying to get a local file:
Resultado.js:
Resultado.js:
componentWillMount(){
axios.get('../config/db.json')
.then(function(response){
alert('ok');
})
.catch(function(error){
alert('error');
});
}
但是,我收到一个错误:
But, I am receiving an error:
尝试在空对象引用上调用虚拟方法boolean java.lang.String.equals(java.lang.Object)"
Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null object reference
文件存在于路径上
我的文件 db.json:
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"}]
推荐答案
只需从json
文件中导入数据即可使用
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,
}
....
}
这篇关于如何使用 axios 获取本地文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文