在业务场景中,有时候会遇到这样的情况:
父组件A给子组件B传值,B组件又继续传递给C,最终执行的是C。
但是B组件并不需要使用A组件传过来的值,B组件只是起了传递作用,
此时可以使用$attrs和$listeners的方法来传递;中间组件B只需要v-bind="$attrs" v-on="$listeners"就可以。
父组件A:
<transition name="fade" mode="out-in">
<component
:is="currentComponent"
v-if="viewFlag"
:bd-code="bdCode"
:current-scene-num="currentSceneNum"
@initBdCode="initBdCode"
@getType="getType"
@hideFotterTable="hideFotterTable"
></component>
</transition>
import SmartBuilding from './components/SmartBuilding'
components: {
SmartBuilding,
},
子组件B:
<ProgressManagement v-bind="$attrs" v-on="$listeners"></ProgressManagement>
import ProgressManagement from './view/ProgressManagement/index.vue'
components: {
ProgressManagement,
},
孙组件C:
props: {
bdCode: {
//点击场景的标段
type: String,
default: ''
},
}