Skip to content

Instantly share code, notes, and snippets.

@srkama
Created June 8, 2017 05:17
Show Gist options
  • Select an option

  • Save srkama/374531b52d86947235641fbfa2f0698c to your computer and use it in GitHub Desktop.

Select an option

Save srkama/374531b52d86947235641fbfa2f0698c to your computer and use it in GitHub Desktop.
JS Bin // source http://jsbin.com/yurubeneci
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<script src="https://unpkg.com/vue"></script>
<script src="https://cdn.jsdelivr.net/lodash/4.17.4/lodash.core.min.js"></script>
</head>
<body>
<div id="app">
<input type="text" v-model='userInput'>
<button v-on:click="addTodo">Add todo</button>
<ul>
<li v-for="todo in todos" v-on:click="deleteTodo(todo)">
{{todo.task}}
<li>
</ul>
</div>
<script id="jsbin-javascript">
new Vue({
el: '#app',
data: {
todos: [],
userInput:''
},
methods: {
addTodo: function(){
console.log("add todo Called");
if(this.userInput.trim() === ''){
return;
}
var newTodo = {
id:_.uniqueId(),
task: this.userInput
}
this.todos.push(newTodo);
},
deleteTodo: function(todo) {
console.log(todo.id)
id = todo.id
for(i=0;i<this.todos.length;i++) {
if(this.todos[i].id == id){
this.todos.splice(i,1);
}
}
console.log("delete Todo");
}
}
});
</script>
<script id="jsbin-source-javascript" type="text/javascript">new Vue({
el: '#app',
data: {
todos: [],
userInput:''
},
methods: {
addTodo: function(){
console.log("add todo Called");
if(this.userInput.trim() === ''){
return;
}
var newTodo = {
id:_.uniqueId(),
task: this.userInput
}
this.todos.push(newTodo);
},
deleteTodo: function(todo) {
console.log(todo.id)
id = todo.id
for(i=0;i<this.todos.length;i++) {
if(this.todos[i].id == id){
this.todos.splice(i,1);
}
}
console.log("delete Todo");
}
}
});</script></body>
</html>
new Vue({
el: '#app',
data: {
todos: [],
userInput:''
},
methods: {
addTodo: function(){
console.log("add todo Called");
if(this.userInput.trim() === ''){
return;
}
var newTodo = {
id:_.uniqueId(),
task: this.userInput
}
this.todos.push(newTodo);
},
deleteTodo: function(todo) {
console.log(todo.id)
id = todo.id
for(i=0;i<this.todos.length;i++) {
if(this.todos[i].id == id){
this.todos.splice(i,1);
}
}
console.log("delete Todo");
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment