2

I have a component with nested properties:

 data () {
   return {
     config: {
       headers: ['a', 'b', 'c'],
       pagination: {
         currentPage: externalService.data.page
         totalPages: externalService.data.totalPages
       }
     }
   }
 }

When externalService.data.totalPages is changed (by other component), the child components are not reactive to this, since maybe the nested reference in config was changed, but not config itself.

I can use watchers to solve it, but I wish to know what would be the declarative (and optimal) solution for it. I'm not a fan of imperative approach when it comes to ClientSide.

0

1 Answer 1

1

I assume that externalService.data.totalPages is an integer. Integer are passed by value and not by reference. So it's a completely normal behavior an you should indeed use a watcher.

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

4 Comments

Thanks. I decided to simply wrap the primitive props with an object, so instead of watching, the reactive nature simply works.
Yes, that's actually the best solution
Chen, could you elaborate on what you mean by wrapping the primitive props with an object?
@HJohnson like from 1 to {value: 1}

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.