【发布时间】:2018-12-04 11:54:26
【问题描述】:
我有以下功能来自:https://github.com/anaida07/MEVN-boilerplate/blob/master/client/src/components/EditPost.vue
methods: {
async getPost () {
const response = await PostsService.getPost({
id: this.$route.params.id
})
this.title = response.data.title
this.description = response.data.description
// this.$router.push({ name: 'Posts' })
},
我正在学习 MEVN。我想知道是否有在不使用 async/await 的情况下编写相同的函数。我目前想出了以下几点:
methods: {
getPost () {
const response = PostsService
.getPost({
id: this.$route.params.id
})
this.title = response.data.title
this.description = response.data.description
//this.$router.push({ name: 'Posts' })
},
但我在控制台日志中收到错误消息:挂载钩子错误:“TypeError: response.data is undefined”。任何帮助将不胜感激。
【问题讨论】:
-
是你不想要
async-await语法的原因吗? -
由于某种原因它不适用于我的 webpack 版本
标签: express vue.js async-await