父组件传值给子组件
父组件需要做的内容
//父组件初始化 要传给子组件的数据
data() {
return {
isCollapse: false,
tabShow:{name:'',name1:''}
};
},
//这里是 嵌入在父组件中的 子组件
//:isCollapse="isCollapse" :tabShow='tabShow' 这是在给子组件传值
<Header @changCollapse="fromChild" :isCollapse="isCollapse" :tabShow='tabShow' />
子组件需要做的内容
//与data平级 子组件进行参数接收使用
props: ["isCollapse",'tabShow'],
子传父值
父组件需要做的内容
//changTabShow 这个是在子组件 传入的名字 tabShow 是父组件使用的方法
<router-view @changTabShow='tabShow'></router-view>
//child 是子组件传过来的 参数
tabShow(child){
//接收到后 就可以进行参数替换了
this.breadcrumbList = child;
}
子组件做的事
//1.传参:使用$emit(String,data)方法向父组件传递参数,
//第一个参数为父组件接受参数的方法名称,第二个参数为子组件要传递的参数
this.$emit('changTabShow',this.breadcrumbList);