0

I'm trying get a insertion into an object at Vue, but I can't...

data: {
    formValid: {},
    buttonIsDisabled: true,
    statusModal: 'active',
},
methods: {
    closeModal() {
        this.statusModal = ''
        this.formValid.test = "test"
    }

},
watch: {
    formValid: {
        handler(o, n) {
            console.log(o)
            console.log(n)
        },
        deep: true
    }
}

When I do 'this.formValid.test = "test"' I don't go to Watch, but if I have this object into of the formValid and I change it, in this case, I go to Watch.

Do you know how can I get this event?

Gustavo Rey
  • 115
  • 9

1 Answers1

1

You cannot add reactive properties to an object on the fly with Vue2 like this. You'll need to either define them in data:

data: {
    formValid: {
        test: '',
    },
    buttonIsDisabled: true,
    statusModal: 'active',
},

or use:
Vue.set(this.formValid, 'test', 'test');

Thomas
  • 6,325
  • 4
  • 30
  • 65