组件

在 Vue 中注册组件:

 Vue.component("todo-item",{
        template:"<li>这是组件</li>"
 })

注册全局组件,必须在实例化vue前注册,否则页面是不会显示的;

将数据从父作用域传到子组件,需要在子组件中定义一个属性props接收数据,并在html中用v-bind把定义的props属性绑定在循环变量上 (item)

Vue.component("todo-item",{
        template:"<li>{{todo}}</li>",
        props:["todo"]
    })
    var vm=new Vue({
        el:"#app",
        data:{
            name:"zyy",
            age:23,
            see:false,
            ayy: ["aaa","bbb","ccc"]
        }
 });

  

 <todo-item v-for="item in ayy" v-bind:todo="item"></todo-item>

  

猜你喜欢

转载自www.cnblogs.com/yongyang/p/8922708.html