父组件通过 直接传值 传递 backgroundcolor 给子组件
父页面
<template>
<div>
<!-- 选项卡子组件 -->
<Child backgroundcolor="red"/>
</div>
</template>
子组件接收父组件传递的 backgroundcolor,并在渲染时根据条件(例如 label_index)使用它。
<div class="left_content">
<div
:style="{backgroundColor: label_index === index ? backgroundcolor : ''}"
>
</div>
</div>
在子组件模板中,使用 :style 动态绑定 backgroundColor 样式。如果当前标签是选中的(label_index === index),那么背景颜色会使用父组件传递的 backgroundcolor 值(例如 'red'),否则不设置背景色(为空字符串 '')。








![[代码随想录Day24打卡] 93.复原IP地址 78.子集 90.子集II](https://i-blog.csdnimg.cn/direct/3a0df6c6ff5d44a6a5e1c7987cc7adf7.png)










