[英][vue]: how to add dynamic class using css modules along with normal class css on the same element in Vue?
For example when i use the scope i write the template with the scope rules, and the code will be例如,当我使用范围时,我使用范围规则编写模板,代码将是
<div
class="item ripple"
v-show="tabList.length > 0"
:class="{'item-on':currentTabActive==index}"
v-for="(item,index) in tabList"
:key="index"
@click="checkTab(index)"
>
</div>
but when i use the css modules, i try the code style like但是当我使用 css 模块时,我尝试使用类似的代码样式
<div :class="[{'$style.red': true},'$style.bold']">hhhhhh</div>
or that或者那个
<div :class="{'$style.red': true},'$style.bold'">hhhhhh</div>
or like that或者像那样
<div :class="{'$style.red': true, '$style.bold'}">hhhhhh</div>
I wonder what's the right way to do?我想知道正确的做法是什么?
Is this what you want?这是你想要的吗? Don't put
$style.red
inside string '$style.red'
, instead if you want to interpolate it, use [$style.red]
.不要将
$style.red
放在字符串'$style.red'
,如果要插入它,请使用[$style.red]
。 $style.red
works jut like normal javascript variable. $style.red
就像普通的 javascript 变量一样工作。
<div
v-show="tabList.length > 0"
:class="[
'item',
'ripple',
{[$style.red]: isRed},
$style.bold,
{'item-on': currentTabActive==index}
]"
v-for="(item,index) in tabList"
:key="index"
@click="checkTab(index)">
</div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.