Beusebiu
Beusebiu

Reputation: 1513

Value is changed just in methods, VueJs

I have a value with false default value, and inside a watch (for another value) I have chage it's value, but the value is changed just there, on second Click (event), the value is changed. Not sure why.. The value is change when I trigger that event twice..

<template>
   <h1>{{hide_confidence}}</h1> //HERE IS NOT CHANGED
</template>

...
  data() {
    return {
      mainSelect: '',
      hide_confidence: true
    };
  },
   watch: {
        mainSelect(value) {
            if (value !== "" && value !== "none") {
                this.hide_confidence = false;
                // this.confidence_score = "";
            } else {
                this.hide_confidence = true;
            }

            console.log("Value: ", this.hide_confidence);  //HERE IS CHANGED
        },

        hide_confidence(value{
            console.log("Value: ", value);  //HERE IS NOT CHANGED
        }
   }

...

Upvotes: 0

Views: 33

Answers (1)

Mr. Perfectionist
Mr. Perfectionist

Reputation: 2746

watch is not a method to change your data permanently. Just you can play with other properties with changing it temporary.

If you want to change a value permanently then you have to call an event.

Please take look in details here: https://v2.vuejs.org/v2/guide/computed.html#Computed-vs-Watched-Property

Upvotes: 1

Related Questions