dimanche 23 juillet 2017

Checkbox not being checked using VueJS 2

I use Axios to GET data from my server. Basically, what I want to achieve is use the response from the GET request and get the data to set the checkbox to true or false depending on the response.

But the problem is, it does not set the checkbox to true or false. But rather, the value of this.checked will always be "".

Here is my code:

 <template>
        <input type="checkbox" value="Yes" v-model="checked">Yes</label> 
 </template>

export default {
  data () {
    return {
      checked: ''
    }
  }


  ...
  ...

 created () {
    ...
    ...
    if ((response.data.categoryTypeId) === noSubCat) {
      // checkbox is not checked
      this.checked === false
    } else {
      // checkbox is checked
      this.checked === true
    }
  }
 }




Aucun commentaire:

Enregistrer un commentaire