分為三個部分:
1.template模版:
1
2
3
4
5
6
|
<script type="text/x-template" id="todo-form-template">
<form v-on:submit.prevent="addtodo(newtodo)">
<input type="text" v-model="newtodo.title">
<button type="submit">提交</button>
</form>
</script>
|
2.vue.js的js操作:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
Vue.component('todo-form',{
template:'#todo-form-template',
props:['todos'],
data(){
return {
newtodo:{id:null,title:'',completed:false}
}
},
methods:{
addtodo(newtodo){
this.todos.push(newtodo);
this.newtodo = {id:1,title:'',completed:false};
// console.log(this.newtodo);
},
}
});
|
3:html部分:
1
|
<todo-form :todos="todos"></todo-form>
|
分三部分完成組件的構建,html提供容器,template編寫詳情,js操控流程(數據操作,將template填充到html等),大體概念是這樣,還需繼續深入