<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>TodoList組件拆分</title>
<script src="vue.js"></script>
</head>
<body>
<div id="root">
<input v-model="inputValue"/>
<button @click="handleClick">提交</button>
<ul>
<todo-item v-for="(item,index) of list" :key="index" :content="item"></todo-item>
</ul>
</div>
<script>
Vue.component('todo-item',{
props:['content'],
template:'<li>{{content}}</li>'
})
new Vue({
el:"#root",
data:{
inputValue:"",
list:[]
},
methods:{
handleClick: function(){
this.list.push(this.inputValue);
this.inputValue=" "
}
}
})
</script>
</body>
</html>