A
A
Alexey Bugaev2020-06-22 10:19:16
Vue.js
Alexey Bugaev, 2020-06-22 10:19:16

How do get and set work in computed?

Hello everyone, I'm starting to learn vue . And a question about vuex. There is a field whose value is pulled from store. The documentation recommends doing this through computed. In a way that is not clear to me, a getter and a setter are implemented there. The message property is an object and its getter, as well as an unnamed setter. It seems to me that a getter without a name in native js just won't work. How does it work in Vue? because it looks like magic to me. I refer to {{message}} and how its nameless getter then works, I can’t reproduce this behavior in js. My assumption: since in computed all properties are objects, when accessing any such object, vue launches its expression method, which includes user-defined functions and getters as well.
Good people, explain the logic.
link to example:

https://vuex.vuejs.org/guide/forms.html#two-way-co...

and screenshot5ef059ac374d1830134156.png

Answer the question

In order to leave comments, you need to log in

2 answer(s)
H
hackteck, 2020-06-22
@aleksei13b

Yes , this is how it works

D
Dmitry Belyaev, 2020-06-22
@bingo347

This is not a getter and setter without a name, these are methods with the names get and set.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question