这是模型
class Search{
constructor(address) {
this.address = address;
}
async getResults() {
try {
const res = await axios(`https://maps.googleapis.com/maps/api/geocode/json?key=${config.key}&address=${this.address}`)
this.result = res.data.results[0].formatted_address; //set the results to result in 'this'.
} catch(error){
console.log(error)
}
}
}
这是控制器
const state = {};
state.search = new Search(address);
state.search.getResults();
console.log(state.search.result);
为什么控制器'console.log(state.search.result)'中的结尾日志语句返回未定义?
我该怎么做才能访问“结果”变量?