jurandou
jurandou

Reputation: 134

Vuejs - change boolean if textarea not empty

I'm trying something i guess very simple :

<textarea name="ask" class="form-control" v-model="text"></textarea>

And the vue :

    data: {
      showLabel: true,
      text: ''
    },
    methods: {
      textareaValue(){
        return this.text
        if(this.text != '') {
          this.showLabel = false
        }
      }
    }

I can see the 'text' data value change in the console, but the showLabel boolean nerver turns to false as required in the test() method.

Any suggestion is very welcome.

Thanks !

Julien

Upvotes: 1

Views: 700

Answers (1)

motia
motia

Reputation: 1999

You should check computed properties. It suits your use case.

You should declare the showLabel as a computed property and not in your data:

computed: {
  showLabel () {
     return !this.text
  }
}

Upvotes: 2

Related Questions