1

I am aware of deep watching of properties using the handler in the "watch" section, but I am not seeing how to make vue deep watch in a getter/setter computed property.

Essentially I have something like this, of which vue is not able to observe the changes.

How do I tell vue to observe the changes of "someComputedProperty"?

computed: { 
    someComputedProperty: {
      set (value) {
        this.someComputedPropertyObject[this.someOtherObject.id] = value;
      },

      get () {
        return this.someComputedPropertyObject[this.someOtherObject.id];
      }
    }
  }

Thanks in advance,

Erion

2
  • Computeds don't work like that. This is the case for a watcher. Commented Sep 13, 2021 at 6:37
  • Estus, thanks, but in my situation a watcher would not make a difference. I am looking and reasonably thinking that Vue should detect that the objects referenced in the computed property changed and should be able to notify of the change. @DecadeMoon’s recommendation is closer to what I was thinking. Commented Sep 13, 2021 at 13:19

1 Answer 1

2

If someComputedPropertyObject is a Vue computed property, its value won't be made observable by design (if it creates a new object).

Furthermore, does someComputedPropertyObject have the this.someOtherObject.id property defined upfront? If not, you're creating a new property which Vue cannot observe. Use Vue.set (or this.$set) instead.

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

1 Comment

Thanks for your thoughts. I will give that Vue.set a try. The object [this.someOtherObject] is a computed property (using a getter/setter) and it's the result of a user interaction.

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.