如何返回axiosgetvalue而不是[objectPromise]?
即使我在 console.log 中获得值,Axios get 函数也总是返回 Promise
我在我的 vue js 函数中使用了这段代码
async encFolderID(_id){
if(_id > 0){
await axios.get(base_url+'Main/Process/FilesStorage/encFolderID/'+ _id).then(response => {
return response.data.enc_id;
})
}
},
回答
您不需要使用.then(). 只是async和await。
这是您应该如何使用它们:
async encFolderID(_id){
if(_id > 0){
const resp = await axios.get(base_url+'Main/Process/FilesStorage/encFolderID/'+ _id);
return resp.data.enc_id
} else ...
},
- 谢谢你的回答。我可以使用这样的功能吗?:id="encFolderID(folder.id)",我正在尝试使用该函数设置 ID。