In the react code, a map component needs to be rendered, and a json data is requested. It is expected that the json data will be injected into the map component after the request is successful, but what is seen in the console is that the content in index.html is returned. content, and no json data is returned.
I tried requesting other json files or a non-existent json file, and the content in index.html was also returned
componentWillMount() {
fetch('../data/wuhan.json')
.then(function(response) {
return response.json();
})
.then(function(json) {
echarts.registerMap('wuhan', json);//注冊地圖組件
})
.then(function() {
this.updataSeries();//處理series
})
};
Check the requested json in the console and return the content in index.html in the public path
學(xué)習(xí)是最好的投資!
fetch
說白了就是個(gè)ajax
請求,ajax
必須在http
協(xié)議下運(yùn)行,放進(jìn)public
目錄下,直接fetch('/wuhan.json')
Try it