Are Getters reactive by default? #513
-
Vue 3, using setup; ` setup() {
` or ` setup() {
` Which is reactive, and if getters are not, then why have them? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Getters are computed properties under the hood. I don't really understand your question. Another way of writing it is: setup() {
const user = useUserStore()
const username = toRef(user, 'username')
// or if extracting multiple ones
const { username } = toRefs(user)
return {
username
}
} |
Beta Was this translation helpful? Give feedback.
-
Thanks, you highlighted my question. "Getters are computed properties under the hood.", However in the setup code I need to wrap with "username: computed(() => user.username),". Does this not double up computed(computed(variable))? Or am I missing something? Bob |
Beta Was this translation helpful? Give feedback.
Getters are computed properties under the hood. I don't really understand your question. Another way of writing it is: