Adding new elements into array evento works fine when checking the checkbox, but how can I delete an element when I uncheck the checkbox?
Play with it: https://codesandbox.io/s/heuristic-currying-uqib1?file=/index.html
v-model is not an option because I'm working with a very complex structure that comes from GraphQL, and a vuex store
<div id="myapp">
<!-- Checkboxes list -->
<ul>
<li v-for="lang in languages">
<input
type="checkbox"
v-bind:value="returnArray(lang)"
v-bind:checked="evento.includes(lang)"
v-on:input="evento = $event.target._value"
/>{{ lang }}
</li>
</ul>
evento : {{ evento }}
</div>
<script>
var app = new Vue({
el: "#myapp",
data: {
languages: [
"PHPPPPPPPPPPP",
"Vue.js",
"Java",
"C",
"AngularJS",
"jQuery",
"JavaScript"
],
evento: []
},
methods: {
returnArray: function (lang) {
console.log("lang: " + lang);
let arreglo = [];
console.log("evento: " + JSON.stringify(this.evento));
// agregar dentro del arreglo la seccion si no existe dentrol del evento
// add language into array if does not exist in evento
if (!this.evento.includes(lang)) {
arreglo.push.apply(arreglo, this.evento);
arreglo.push(lang);
console.log("ENTRO!");
}
console.log("arreglo: " + JSON.stringify(arreglo));
console.log("+++++++++++++: ");
return arreglo;
}
}
});
</script>