1.父组件向子组件传值:
components: {'child'}引入子组件后,import引入child子组件路径;
return{}中定义->remarkForm:{}, 然后,父组件代码: <template> <div v-show="curTab===0"> <!--子组件child,将remarkForm赋值之后,放入子组件,同时,子组件那边将remarkForm放入prop:{}--> <child :remarkForm="remarkForm" ></cild> </div> <template> 子组件代码: 添加props:{ remarkForm:{ type:Object, } }props中的remarkform用于接收父组件的传值
2.子组件向父组件传值:
子组件定义方法,使用$emit声明传值:
<a @on-change='transData(v)'></a> transData(v){this.$emit('getChildData',v);}
父组件定义接收方法:
return { name:'', } getChildData(v){ this.name=v; } 这样就拿到子组件的值了 另外还有一种方法,子组件调用父组件的方法:this.$parent.fatherMethod(); 在fatherMethod()中可以给个返回值,子组件需要的返回值