父组件传子组件参数:
在父组件引用组件中用 :<子组件prop参数名>="<父组件参数名>"传出
<searchicst v-if="type=='icst'" :id="type" :thisdata="thisdata" :funcSearchSon="getdata" ></searchicst>
.
.
.
import searchclkd from "./model/search_clkd.vue";
export default {
components: {
searchicst,
},
在子组件中props接收
props: {
type: {},//各项目传入的type判断选择的组件
thisdata:{},
},
父组件调用子组件方法及参数:
引用子组件后,为子组件添加ref值: ref="searchclkd2"
<searchclkd2 :id="id+'Sec'" :thisdata="thisdataSec" ref="searchclkd2"></searchclkd2>
在script内的方法事件中用this.$refs.<ref值>.<子组件方法及参数>
jiansuo(){
this.selectResult=[];
var NUM=this.$refs.loopbox.thisindex;
var ss=this.$refs.searchclkd2.jiansuo();
子组传给父组件件参数:
子组件事件方法结尾处添加$emit(xxx,xxx),触发自定义事件,来给触发监听事件
this.$emit('funcSearchSon',[this.selectResult,ss]);
在父组件中引用处添加@<子组件方法>="<父组件方法>"传给父组件方法内使用,值为val
<searchclkd :id="type" :thisdata="thisdata[1]" @funcSearchSon="getsearchdata"></searchclkd>
.
.
.
methods:{
getsearchdata(val){
this.$emit('funcSearchFather',val);
}
}
组件插槽内传值给插槽子组件参数:
组件内部引入loopbox组件,loopbox内部安插插槽放置put组件,此时loopbox的数据如何传入put内部,大致和父传子类似。
loopbox引用组件位置的template 插槽点设置插槽参数值:v-solt="<插槽参数名>",如 v-slot="slotProps"
<loopbox :id="id" :max="thisdata.options.max" :firstlist="thisdata.options.firstlist" >
<template v-slot="slotProps" >
<put
ref="myput"
:id="id+'_myput'+slotProps.thislength"
style="float:left;margin:0px 4px 0px 0px;"
></put>
</template>
</loopbox >
loopbox组件内部,槽点slot 内设置传参参数如 :thislength="index",再者由上部显示,
loopbox引用组件位置内的插槽点,引出参数传给put组件内,<插槽参数名>.<参数名>如:slotProps.thislength,插槽子组件用prop接收后可用
<template>
<div>
<div v-for="(thiskey,index) in ergodic" :key="index">
<slot :thislength="index" ></slot>
</div>
</div>
</template>
子组件调用父组件的方法参数:
使用this.$parent.<父组件名>.<父组件方法参数>