How to get id from the checkbox to check if is checked or not in vue3
<div>
<input
type="checkbox"
class="delete-checkbox"
:id=this.products[index].sku
@click="setDelete(this.products[index].sku)" />
</div>
I'm building an vuex app and I try to start an event when this checkbox is checked but I don't know how to do this.
Can somebody help me, please?
Pls check out following snippet:
const demo = {
data() {
return {
products: [{sku: 1}, {sku: 2}, {sku: 3}],
};
},
methods: {
setDelete(id) {
console.log('event fired for: ' + id)
}
},
};
Vue.createApp(demo).mount("#demo");
<script src="https://unpkg.com/vue@next"></script>
<div id="demo">
<li v-for="(product, idx) in products" :key="idx">
<input type="checkbox" class="delete-checkbox" :id="product.sku" @click="setDelete(product.sku)">
</li>
</div>