vuejs v-model, multiple checkbox and computed property

后端 未结 2 875
栀梦
栀梦 2021-01-13 14:35

I am trying to use multiple checkboxes in single file component. And I need to computed property, but I have boolean newVal instead of array in my setter. Here is my code:

2条回答
  •  不要未来只要你来
    2021-01-13 14:47

    Here it is the working version:

    var demo = new Vue({
      el: '#demo',
      data: {
        checkedNames: []
      }
    })
    
    

    Checked names: {{ checkedNames }}

    if you want to use a computed property you can use it in this way:

    var demo = new Vue({
      el: '#demo',
      data: {
        checkedNames: []
      },
      computed : {
        checkedComputed () {
          return this.checkedNames
        }
      }
    })
    
    

    Checked Names : {{ checkedComputed }}

提交回复
热议问题