template>
<div>
<div class="main-tabs-items" v-for="(item, index) in 3" :key="index" :style="getBackgroundColor(index)">
1
</div>
</div>
</template>
<script>
export default {
methods: {
getBackgroundColor(index) {
const colors = ['red', 'green', 'blue']; // 设置不同的颜色值
return `background-color: ${colors[index]};`;
}
}
}
</script>
<style>
.main-tabs-items {
width: 100px;
height: 100px;
color: white;
text-align: center;
line-height: 100px;
}
</style>
vue2中多个div动态背景颜色
最新推荐文章于 2024-07-04 15:23:33 发布