【发布时间】:2021-01-24 17:19:24
【问题描述】:
我正在尝试从服务的 axios 响应返回数据,但我将始终从服务undefined 接收数据,但在服务内部我有数据。你能告诉我我做错了什么吗?
这是我的服务的样子:
import axios from 'axios';
export default {
async fetchById (articleId) {
await axios.post('/api/article', { id: articleId })
.then(function (response) {
console.log('axios', response) // valid response
return response.data
})
.catch(function (e) {
console.error('error', e);
});
}
}
还有我在组件中的用法:
async created () {
const article = await articleService.fetchById('12345')
console.log('article', article) // there I have undefined
}
【问题讨论】:
标签: javascript vue.js axios nuxt.js