Watch variable change in a component

Hi,

i have a Vue component that i have some text fields, i would like to monitor if some of them change and set a boolean flag in the case. The value of the text field is stored in the variables txtField1, txtField2 etc.

I’m thinking of using watch for this, but I don’t know if it’s the best way to handle the scenario,
But even using watch does nothing:

watch: {
      txtField1: function () {
      flag = true;
      console.log ("modified field");
},

Is textField1 a reactive property? i.e data, computed, or prop?

Can you recreate your issue in a jsfiddle for us?

2 Likes

I think this should work

<input type="text" id="txtField1" v-model="txtField1" @change="flag = true" >