需求:List属性值传Detail中,我是先传index中再传Detail,其中index是List和Detail父(兄弟之间也能传输)
子传父(List传index)
List文件方法中定义
this.$emit('operateval', operate)
this.$emit("function",param);
其中function为父组件定义函数,param为需要传递参数
index文件中接受
在父组件中子组件引用处添加函数
v-on:function="function1";
其中function为子组件中定义函数,function1为父组件定义函数--用于接收子组件传值并进行相应数据处理,可定义为同一名称
v-on: 可用 @ 代替 @function="function1" ,@ 为 v-on:的简写
<list @operateval="operateval" />
methods: {
operateval(val) {
this.operate = val
}
完成子传父
接下来父传子(index传Detail)
父(index)文件
<detail :operate="operate" />
子(Detail)
props: {
operate: {
type: String,
default: ''
}
}