fetchMockData = () => {
fetch('mock-data/selectData01.json')
.then(
(res) => {
return res.json();
})
.then(
(data) =>{
//console.log(JSON.stringify(data))
var returnData = JSON.stringify();
console.log(typeof(returnData))
console.log('电信 ===', data['dataChinaTelecom']['emergencyTableData'])
return data['dataChinaTelecom']['emergencyTableData']
})
.catch(
(e) => {console.log(e.message);
});
}
async getData() {
const _self = this;
try {
let response = await fetch('mock-data/selectData01.json').then(function(response) {
return response.json();
}).then(function(responseThenData) {
//console.log('responseThenData =',responseThenData);
return responseThenData
}).catch(function(e) {
//console.log("Oops, error");
});
let responseData = response;
console.log('responseData =',responseData);
return 'xx';
} catch(e) {
console.log("Oops, error", e);
}
}
componentDidMount() {
const _self = this;
var key = true;
console.log('this.getData =', this.getData());
let dataPromise = this.getData();
console.log('dataPromise =',dataPromise)
var a = dataPromise.resolve('xx');
// Promise {[[PromiseStatus]]: "resolved", [[PromiseValue]]: "xx"}
a.then(function (result) { console.log('result =',result) })
// var key = true;
// new Promise(function(resolve, reject){
// if(key){
// resolve('成功了')
// }else{
// reject('被拒绝')
// }
// }).then(function(value) {
// console.log(value); // key=true 123
// }, function (rej) {
// console.log('---------result reject');
// console.log(rej);
// })
}

方法getdata 你return的是"xx",一个字符串。不是一个promise对象。不太明白你这样写的目的,建议看下
阮一峰ES6的promise