我的服务器Api响应是这样的:
{"data":{"databases":["rohit_one_test"]},"error":null,"success":true}我使用axios和vue js来进行这样的调用。
//axiosget函数
import axios from 'axios';
export function axiosGet (url) {
return axios.get(url,{ headers: {'Authorization': 'Basic token'}})
.then(function (response) {
return response.data.data;
})
.catch(function (error) {
return 'An error occured..' + error;
})
}我在别的地方叫它:-
showdblist(){
this.url=API_LOCATION+"/tools/mysql/resources/databases/"+this.domain;
this.dbs=axiosGet(this.url);
console.log(this.dbs);
}当我记录dbs变量时,它是这样的。
屏幕截图在这里:--https://prnt.sc/kmaxbq
我的问题是如何在dbs变量中访问我的数据库的名称?
发布于 2018-08-24 14:45:10
这是一个返回的promise,所以从promise resolve中返回什么也不做。取而代之的是,把它当做一个回报的承诺,并像这样解决它:
async showdblist() {
this.dbs = await axiosGet(this.url)
// now this.dbs is correct
}如果你不能使用async/await,就把它当做一个常规的承诺:
axiosGet(this.url)
.then((response) => {
this.dbs = response.data.data
})https://stackoverflow.com/questions/51998541
复制相似问题