Created
June 24, 2017 02:50
-
-
Save rye761/b3c3e112da4a97d976463c7424dcd9c2 to your computer and use it in GitHub Desktop.
Todo App in Vue.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>Todo App</title> | |
<meta charset="utf-8"> | |
<script src="https://unpkg.com/vue"></script> | |
</head> | |
<body> | |
<div id="app"> | |
<h1>Todo App</h1> | |
<todo-form @todo-created="addTodo"></todo-form> | |
<todo-list :todos="todos"></todo-list> | |
</div> | |
<script type="text/javascript"> | |
// Our app here | |
Vue.component('todo-form', { | |
template: '<form @submit.prevent="todoEvent"><input type="text" v-model="newTodo">' + | |
'<input type="submit" value="Add"></form>', | |
data: function () { | |
return { | |
newTodo: '' | |
} | |
}, | |
methods: { | |
todoEvent: function () { | |
this.$emit('todo-created', this.newTodo); | |
this.newTodo = ''; | |
} | |
} | |
}); | |
Vue.component('todo-list', { | |
template: '<ul><li v-for="todo in todos">{{ todo }}</li></ul>', | |
props: ['todos'] | |
}); | |
new Vue({ | |
el: '#app', | |
data: { | |
'todos': [] | |
}, | |
methods: { | |
addTodo: function (todo) { | |
this.todos.push(todo); | |
} | |
} | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment