VUE 父子组件传值与传事件

传值(父->子)

以下:后面均为父向子传递的值

<todo-item
         v-for="(item,index) of list"
         :key="index"
         :content="item"
         :index="index"
         @delete="handleDelete"
         ></todo-item>

子可用如下 采用属性赋值

 Vue.component('todo-item',{
    
    
            props:['content','index'],
            template: '<li @click="handleClick">{
    
    {content}}</li>',
            methods: {
    
    
                handleClick:function(){
    
    
                    this.$emit('delete',this.index)
                }
             },
        })

子向父传事件 采用 emit发散出去(带有事件句柄,参数)
父组件接受后 进行事件响应

猜你喜欢

转载自blog.csdn.net/qq_42676042/article/details/105967400
今日推荐