Vue.component():注冊組件
my-component-li:自定義組件的名字
template:組件的模板
利用 props屬性傳遞參數,默認規則下props屬性里的值不能為大寫。
1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <meta charset="UTF-8"> 5 <title>Title</title> 6 </head> 7 <body> 8 <div id="app"> 9 10 <!--自定義組件,傳遞給組件中的值用 props--> 11 <ckfuture v-for="item in items" v-bind:ck="item"></ckfuture> 12 13 </div> 14 15 <!--引入vue.js 包--> 16 <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script> 17 <script> 18 //定義一個Vue組件component 19 Vue.component("ckfuture",{ 20 props:['ck'], 21 template:'<li>{{ck}}<li/>' 22 }); 23 24 var vm=new Vue({ 25 el:"#app", 26 data:{ 27 items:["java","C#","RN"] 28 } 29 }); 30 31 </script> 32 </body> 33 </html> 34