感谢前端大佬给我写的demo
<template >
<parentA>
<childB v-if="showList1" @switch-tab="switchTab">
child B
</childB>
<childC v-else>
child C
</childC>
</parent>
</template>
<script>
export default {
methods: {
switchTab(val) {
this.showList1 = val;
}
}
}
</script>
<template class="B">
<button @click="handleDisplay"></button>
</template>
<script>
export default {
methods: {
handleDisplay() {
this.$emit('switch-tab', false);
}
}
}
</script>
本文介绍了一个使用Vue实现的子组件动态切换示例。通过点击按钮触发事件,父组件控制两个子组件childB和childC之间的显示与隐藏。该示例展示了如何通过v-if和v-else结合@switch-tab事件来实现子组件的切换。
4292

被折叠的 条评论
为什么被折叠?



