Evan Summers
Evan Summers

Reputation: 1202

Are Vue 3 `reactive` object getters made into computed values?

In this example, is bookCount memoized the same way as a computed ref is?

const author = reactive({
  name: 'John Doe',
  books: [
    'Vue 2 - Advanced Guide',
    'Vue 3 - Basic Guide',
    'Vue 4 - The Mystery'
  ],

  get bookCount() {
    return this.books.length
  }
})

Upvotes: 0

Views: 419

Answers (1)

Kapcash
Kapcash

Reputation: 6909

No, it is not. The getter will be executed everytime the property is accessed.

You can check it by using the getter in the template, and provoke a template re-render. You'll see the getter will be executed at every render, while a regular computed won't (as long as the value didn't change).

Check out this example on sfc.vuejs.org

Upvotes: 2

Related Questions