Hi All,
I have created a simple
CRUD operation in VueJS.The values are inserting in a list , i can read it from there only and also can delete it from the list. But issue is when i am trying to update any value, its not getting update. Can any one help me out with it. Am i doing anything wrong. Please let me know.
<html>
<head>
<script src="https://cdn.jsdelivr.net/npm/vue"></script>
</head>
<body>
<div id="app">
<form v-on:submit.prevent="addToDo">
<input v-model="currentTodos" type=text><br><br>
<button type="submit">Add To List</button>
</form>
<ul>
<li v-for="(todo, index) in todos">
{{todo}}<button v-on:click="deleteItemFromList(index)">X</button><button v-on:click="updateItemList(index)">#</button>
</li>
</ul>
</div>
<div v-html="htmlContent"></div>
</body>
<script>
new Vue({
el: "#app", // el is the DOM element.
data:{
todos:['push', 'pop', 'paste'],
currentTodos: '',
htmlcontent : "<div><input type="text"></div>"
},
methods:{
addToDo: function(){
this.todos.push(this.currentTodos);
this.currentTodos = '';
},
deleteItemFromList: function(index){
this.todos.splice(index,1)
},
updateItemList: function(index){
this.todos.set(index,1)
}
}
})
</script>
</html>
setmethod.this.todos[index] = newVal. Just change the value of array is fine.