我无法使用此函数返回值,因为它是空的。如何在axios之外设置变量获取
getNameById (id) {
var name = ''
axios.get('/names/?ids=' + id)
.then(response => {
this.response = response.data
name = this.response[0].name
})
.catch(e => {
this.errors.push(e)
})
// Is empty
console.log('Name ' + name)
return name
}
如何访问“then”中的name变量并返回它?
是的,它不会从我回到 – John