Vue Getter &Setter 而不是后端响应中的实际值 [英] Vue Getter & Setter instead of the actual values in backend response

查看:32
本文介绍了Vue Getter &Setter 而不是后端响应中的实际值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Vue 的新手,我很难理解为什么我的问题会发生.

I'm new to Vue and I'm struggling to understand why my problem is happening.

当我调用后端以检索一些数据时,响应如下:

When I make a call to my backend to retrieve some data the response is as follows:

id: Getter & Setter
name: Getter & Setter
season: Getter & Setter
number: Getter & Setter

在 Vue 中,如果我将数据更改为对象而不是函数,我会得到我期望的值.

Within Vue, if I change data to be an object instead of a function, I get the values I expect.

id:10897
name:"Minimum Viable Product"
season:1
number:1

通过阅读 Vue 的文档,我知道数据应该是一个函数,但是我不明白为什么它会影响我获得的数据?

From reading Vue's documentation I know data should be a function, however I don't see why it affects the data I am getting?

我像这样检索数据:

methods: {
     async episodes() {
      const response = await EpisodesService.getAllEpisodes()
      console.log(response)
}

推荐答案

https://vuejs.org/v2/guide/components.html#data-Must-Be-a-Function

您可以将数据更改为对象而不是函数,但不建议这样做.如果 Vue 没有这个规则,点击一个组件会影响所有其他实例的数据.

you can change data to be an object instead of a function, but not recommend. If Vue didn’t have this rule, clicking on one component would affect the data of all other instances.

这篇关于Vue Getter &Setter 而不是后端响应中的实际值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆