vue 自定义组件 component

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  

 

posted @ 2021-01-22 19:37  创客未来  阅读(1092)  评论(0编辑  收藏  举报