vue动态类名的几种方式

1,
<div class="item" :class="{ 'active-tab': activeTab === i.name }" v-for="i in tabList" :key="i.name">
{{ i.name }}
</div>
// active-tab为类名 单独写样式
 用符号连接时要加'' 满足activeTab === i.name时 class类名使用active-tab

2,
<div class="my-list" :class="{ special: userType === '02' }"></div>
// special为类名 单独写样式
 单独单词则不需要加'' 满足userType === '02'时 class类名使用special

3,
// 通过类名传值 控制样式 
// 子组件
<div class="cps-my-default-tab-container" :class="{ 'border-top-style': borderTopStyle, 'border-top-left-radius': borderRadiusTop }"></div>
// border-top-style 类名 单独写样式
// borderTopStyle 为true时 class使用border-top-style
//父组件
eg: <my-default-tab :borderTopStyle="true" />
 // 此时 borderTopStyle 为true 父组件内class使用border-top-style
<script setup>
import { defineProps } from 'vue'
const props = defineProps({
  borderTopStyle: {
    type: Boolean,
    default: false
  },
  borderRadiusTop: {
    type: Boolean,
    default: false
  }
})
</script>

以上为动态类名的基本使用方式,还请大佬多多指教!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值