Skip to content

Instantly share code, notes, and snippets.

@rosd89
Last active August 22, 2017 12:11
Show Gist options
  • Save rosd89/9e8056aeceae4899acfbe3723dcf4a24 to your computer and use it in GitHub Desktop.
Save rosd89/9e8056aeceae4899acfbe3723dcf4a24 to your computer and use it in GitHub Desktop.
Vue·tiful Korea 170823 컴포넌트야 놀자
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>todo</title>
</head>
<body>
<div id="root"></div>
</body>
<script src="https://unpkg.com/vue"></script>
<script type="application/javascript">
Vue.component('todo-content', {
template: `
<div class="todo-content">
<h1>Todo List</h1>
<slot></slot>
</div>`
});
Vue.component('todo-list', {
data () {
return {
items: ['A', 'B', 'C']
}
},
methods: {
completed (item) {
const items = this.items;
const i = items.indexOf(item);
items.splice(i, 1);
}
},
template: `
<ul>
<todo-item
v-for="item in items"
:key="item"
:name="item"
v-on:completed="completed"></todo-item>
</ul>`
});
Vue.component('todo-item', {
props: ['name'],
methods: {
complete () {
this.$emit('completed', this.name);
}
},
template: `<li>{{name}} <button class="btn" @click="complete">완료</button></li>`
});
new Vue({
el: '#root',
template: `
<todo-content>
<todo-list></todo-list>
</todo-content>`,
});
</script>
<style>
.todo-content {
width: 720px;
background: #dddddd;
margin: 0 auto;
padding: 1px 5px 10px 5px;
}
.btn {
clear: both;
float: right;
}
</style>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment