[Vuejs]-Vue filter by checkbox true or false value

0👍

You can add an array of modified list and v-model with your checkbox.Thus you can get the modified list.

new Vue({
  el: '#app',
  data: {
    showChecked: []
  }
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>

<div id='app'>
  <input type="checkbox" value='1' v-model="showChecked" /> element 1</label> <br>
  <input type="checkbox" value='2' v-model="showChecked" /> element 2</label>
  <br> {{showChecked}}
</div>

0👍

You can change the condition of filter to return all entries when the checkbox is empty(this.showUnModerated is false).

return this.listing.listings.filter(listing => (this.showUnModerated ? (1===listing.moderated) : true);

Leave a comment