Created
June 23, 2017 17:43
-
-
Save rye761/ae7743c7e9c153df5848bc8285849083 to your computer and use it in GitHub Desktop.
This file contains hidden or 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>{{ header }}</h1> | |
<todo-form @add-todo="addTodo"></todo-form> | |
<todo-list :todos="todos"></todo-list> | |
</div> | |
<script> | |
Vue.component('todo-form', { | |
template: '<form @submit.prevent="addTodo"><input type="text" v-model="newTodo"><input type="submit" value="Add"></form>', | |
data: function () { | |
return { | |
newTodo: '' | |
}; | |
}, | |
methods: { | |
addTodo: function() { | |
this.$emit('add-todo', 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': [], | |
'header': 'Todo App' | |
}, | |
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