Vue Dynamic V-model Within V-for September 20, 2023 Post a Comment I have the following fieldsets containing checkboxes: Copyand you should loop using v-for like :<fieldsetv-for="(filters, key,index) in availableFilters">Copywhere the filters represents the value, key represents the key like level and ìndex represents the index such 0, using the key item we could access selected like selected[key] so we could bind the checkbox to that property easily.Full examplenewVue({ el: '#app', data() { return { selected: { level: [], subject: [], delivery: [] }, availableFilters: { level: { "UG": 12, "PG": 12, }, subject: { } } } } });Copy<linktype="text/css"rel="stylesheet"href="//unpkg.com/bootstrap/dist/css/bootstrap.min.css" /><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.16/vue.js"></script><divid="app"class="container"><fieldsetv-for="(filters, key,index) in availableFilters"><labelv-for="(count, value) in filters"><inputtype="checkbox":data-filterName="this[filters]":value="value"v-model="selected[key]" @change="onchange"> {{value}} ({{count}}) </label></fieldset><pre>{{selected}}</pre></div>Copy Share You may like these postsVue And Jest Unit Testing ComponentsHow To Use A Vue.js Plugin Inside A Custom Component?Build Leads To Empty Html Page With Syntax Errors When Serving Vue App Using NodePutting Data Inside Prop To Make It Look Tidy Vue.js Post a Comment for "Vue Dynamic V-model Within V-for"
Post a Comment for "Vue Dynamic V-model Within V-for"