0

I have a input checkbox tag which I'm trying to delete after it has been updated in my v-model please how can I go about this.

This is my input tag:

<input
                v-model="checked"
                type="checkbox"
                id=""
                value="jackets"
              >

I get the v-model value property by doing this

{{checked}} 

Please how can I add a delete function to my v-model property in which if I click on the delete function the checkbox would be unchecked.

1 Answer 1

1

If I understood you correctly try like following snippet (just set your checked property to false):

new Vue({
  el: '#demo',
  data() {
    return {
      checked: true,
      filters: [{name: 'XXL', state: false}, {name: 'Grey', state: false}]
    }
  },
  methods: {
    del() {
      this.filters.forEach(f => f.state = false)
    },
    rem(i) {
      this.filters[i].state = false
    }
  }
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="demo">
  <div v-for="(filter, i) in filters" :key="i">
    {{ filter.name }}
    <input
      v-model="filter.state"
      type="checkbox"
      id=""
      :value="filter.name"
    />
    <button @click="rem(i)">X</button>
  </div>
  Remove All
  <input
      type="checkbox"
      id=""
      @input="del"
    />
</div>

Sign up to request clarification or add additional context in comments.

3 Comments

this is what I'm trying to achieve.....imageshack.com/i/pmQZBrAxj
what if I I wanto delete remove just one instead of both like each check v-model property would have a delete property
check again pls

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.