0

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
  }
})
0

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

2 Comments

FYI, you can make bookCount a computed inside the reactive object, and it will work seamlessly :)
It causes some issues with TypeScript though, since it doesn't know the type of this and complains about a circular reference if using author

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.