vue.js自定義標簽(自定義組件)


分為三個部分:
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等),大體概念是這樣,還需繼續深入


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM