2
is part of the HTML code in question:
<div class="row">
<h1>Minha lista de elementos</h1>
<input type="text" class="form-control" v-model="newElement" v-on:keyup.enter="addElement">
<ul>
<li v-for="element in elements">
{{ element.title }}
<a href="#" v-on:click="removeElement($event,$index)">X</a>
</li>
</ul>
</div>
My Javascript code
var hello = new Vue({
el:'#hello',
data:{
msg: "Hello pessoal",
peoples:[
{name: "Maria"},
{name: "Gustavo"},
{name: "Ricardo"},
{name: "Wladimir"}
],
newElement:'',
elements:[]
},
methods:{
addElement: function(){
/* console.log(e); */
var title = this.newElement.trim();
if(title){
this.elements.push({title:title});
this.newElement = "";
}
},
removeElement: function(e,index){
e.preventDefault();
this.elements.splice(index,1);
}
}
});
What happens is that it is deleting the added items, however it is not deleting in the order, could take a look please, I believe it is bullshit.
sorry, but it is still not working, when I click on X to remove, it is removing randomly.
– wladyband
It’s removing from top to bottom regardless of which I click.
– wladyband