//異步獲取本地json文件 handleJson=(name)=>{ return new Promise((resolve,reject)=>{ axios.get(`/border/${name}.json`).then( function(data){ resolve(data) } ) }) } //循環變量獲取對應json文件 handleBorderData=()=>{ var {districts}=this.state; _.forEach(districts,(item)=>{ var name=item.codeName this.handleJson(name).then((data)=>{ gzData[item.code]=data.data console.log('gzData',gzData[item.code][0]) }) }) } async componentDidMount(){ await this.handleBorderData(); }