Vue.js 为什么我的承诺中会出现这个未定义的属性错误消息?

Vue.js 为什么我的承诺中会出现这个未定义的属性错误消息?,vue.js,promise,axios,Vue.js,Promise,Axios,当我的axios调用失败时,catch()中的代码会正确显示err.response.data.message中定义的错误消息 但是当axios调用成功时,我在控制台中遇到以下错误: 未捕获(承诺中)TypeError:无法读取未定义的属性“data” 如何解决这个问题 这是我的axios呼叫代码: mounted () { this.$axios.$get(`http://example.com/wp-json/project/v1/post/${this.$route.params.id

当我的
axios
调用失败时,
catch()
中的代码会正确显示err.response.data.message中定义的错误消息

但是当
axios
调用成功时,我在控制台中遇到以下错误:

未捕获(承诺中)TypeError:无法读取未定义的属性“data”

如何解决这个问题

这是我的
axios
呼叫代码:

mounted () {
  this.$axios.$get(`http://example.com/wp-json/project/v1/post/${this.$route.params.id}`)
    .then((res) => {
      this.title = res.post_title
      this.content = res.post_content
    })
    .catch((err) => {
      this.$toast.error(err.response.data.message)
    })

尝试
res.data.post\u title
而不是
res.post\u title

...
.then((res) => {
  this.title = res.data.post_title
  this.content = res.data.post_content
})
...
Axios返回包含以下信息的对象

{
  data: {},        // the response that was provided by the server
  status: 200,     // the HTTP status code from the server response
  statusText: 'OK',// the HTTP status message from the server response
  headers: {},     // the headers that the server responded with
  config: {},      // the config that was provided to `axios` for the request
  request: {}      // the request that generated this response
}
如果您收到相同的错误,那么可能是服务器端数据格式错误,请尝试console.log响应,并查看服务器端是否存在任何问题

...
.then((response) => {
    console.log(response.data);
    console.log(response.status);
    console.log(response.statusText);
    console.log(response.headers);
    console.log(response.config);
  });
...

您是否
console.log()
检查了
err
的内容?正如错误消息非常清楚地指出的那样,
err.response
未定义。是的,无论axios调用成功与否,它都不起作用。但是$toast.error在axios调用失败时正常工作。这很奇怪