vue父组件与子组件传值

1.子组件--父组件传值emit 通过在子组件上绑定自定义事件,子组件内部通过emit进行数据传送,父组件通过调用函数进行数据接收

<v-child @toparent="getData()">
</v-child>
send(){
this.$emit('toparent',this.str);
}

2.非父组件(平行组件之间)传值空vue对象
通过emit('',数据)发送on接收

method:{
getData(msg){
this.str=msg;
}
}

3.父组件操作子组件refs,使用refs获取到DOM

mounted:{
this.title='hello';
this.$nextClick(function(){
console.log(this.$refs.title.innerHTML);
})
}

slot使用
使用slot添加标签(在template模板内添加)
<slot name="ul-slot">默认显示

组件标签中添加内容,
<ul solt="ul-slot">替换

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容