当前位置:网站首页>Dynamic style binding --style and class
Dynamic style binding --style and class
2022-06-30 20:35:00 【Mr. Liu works hard】
One : dynamic style How to write it
Note before writing :
All have - Of style Attribute names have to be humped , such as font-size To become fontSize
Except binding value , The values of other attribute names should be enclosed in quotation marks , for example
backgroundColor:#00a2ff To write backgroundColor:‘#00a2ff’.
One 1 object form
When we don't create separate css When you file , Write... Directly in the code
<div :style="{ color: activeColor, fontSize: fontSize + 'px' }"></div>
<div :style="{color:(index == 1 ? conFontColor:'#000')}"></div>
perhaps
<div
:style="{
boxSizing:'border-box',
height:29+'px',
top:(valch-1)*29+'px',
background:chose(val.subjectCode),
borderLeft:' 10px ' + ' solid ' + chose1(val.subjectCode
)}" > /<div>
One 2 Array form
<div :style="[baseStyles, overridingStyles]"></div>
<div :style="[{color:(index == 1 ? conFontColor:'#000')},{fontSize:'18px'}]"></div>
One 3 Ternary operator
<div :style="{color:(index == 1 ? conFontColor:'#000')}"></div>
<div :style="[{color:(index == 1 ? conFontColor:'#000')},{fontSize:'18px'}]"></div>
<div
:style="item.layerName === activeLayerName?'font-weight:700' : 'font-weight:400'">
</div>
<!-- Writing a -->
<div :style="[{float: id === '12' ? 'left:'right}]"></div>
<!-- Write two -->
<div :style="float: nameList.length === 20 ? 'height:64px' : 'height:32px' "></div>
<!-- Write three -->
<div :style="{border:( nameId ===item.id ?'2px solid #4C78FF': 'red')}"></div>
One 4 binding data object
<div :style="styleObject"></div>
<script>
data() {
return{
// stay data Define the initial style values in
styleObject: {
color: 'red',
fontSize: '14px'
}
}
}
</scrip>
Two : class How to write it
Two 1 object form
<!-- isActive — Decision value is : true/false -->
<div :class="{ 'active': isActive }">{
{name}}</div>
Two 2 Determine whether to bind a active
<div :class="{'active' : isActive == -2}" >{
{name}}</div>
<div :class="{'active' : isActive == item.nameId}" >{
{item.name}}</div>
Two 3 Bind and judge multiple
Two 3.1 The first one is Separated by commas
<div :class="{ 'active': isActive, 'user': isUser }"></div>
Two 3.2 Put it in data Inside
<div :class="classObject">{
{name}}</div>
<script>
data() {
return {
classObject:{
active: true,
user:false
}
}
}
</script>
Two 3.3 Use computed Compute properties
<div :class="classObject">{
{name}}</div>
<script>
data() {
return {
isActive: true,
isUser: false
}
},
computed: {
classObject: function () {
return {
active: this.isActive,
user:this.isUser
}
}
}
</script>
Two 4 Array form
Two 4.1 Simple arrays
<div :class="[isActive,isUser]">{
{name}}</div>
<script>
data() {
return{
isActive:'active',
isUser:'user'
}
}
</script>
Two 4.2 Array and ternary operator are combined to judge and select the required class
Be careful : After the ternary operator The colon ,
On both sides class You need to put single quotes , Otherwise, it will not render correctly
:class = " [ isActive ? 'active' : ' '] "
perhaps
:class = "[ isActive1 ? 'active' : ' ' ] "
perhaps
:class= " [ isActiveindex ? 'active' : ' ' ] "
perhaps
:class=" [ isActive == index ? 'active' : 'otherActiveClass' ] "
Two 4.3 Array objects combined with dynamic judgment
// This is the front. active You can put no single quotation marks inside the object , This one at the back sort Use single quotes 、
:class="[
{ active: isActive }, 'sort'
]"
perhaps
:class="[
{ active: isActive1 }, ‘sort’
]"
perhaps
:class="[
{ active: isActiveindex }, ‘sort’
]"
边栏推荐
- [1175. prime number arrangement]
- Document contains & conditional competition
- 杰理之检测灵敏度级别确定【篇】
- Scene 299
- 北京大学ACM Problems 1000:A+B Problem
- Huffman tree (I) basic concept and C language implementation
- Encoding type of Perl conversion file
- Client request external interface standard processing method
- Pytorch implements the calculation of flops and params
- 二叉查找树(一) - 概念与C语言实现
猜你喜欢
![Network planning | [five transport layers and six application layers] knowledge points and examples](/img/4f/31acce51b584bed5ef56b2093c4db3.png)
Network planning | [five transport layers and six application layers] knowledge points and examples

AVL平衡二叉树(一) - 概念与C语言实现

AVL balanced binary tree (I) - concept and C language implementation

哈夫曼树(一)基本概念与C语言实现
![Jerry's touch key recognition process [chapter]](/img/ec/25d2d6fd26571e4fb642129a4eee1b.png)
Jerry's touch key recognition process [chapter]

Lambda expression principle analysis and learning (June 23, 2022)

PHP obtains opcode and C source code

Maya House Modeling

PostgreSQL heap堆表 存储引擎实现原理

1、生成对抗网络入门
随机推荐
Golang应用 ━━ 安装、配置与使用hugo博客系统
Client request external interface standard processing method
25: Chapter 3: developing pass service: 8: [registration / login] interface: receiving and verifying "mobile number and verification code" parameters; (it is important to know the application scenario
Jenkins打包拉取不到最新的jar包
originpro 2021 附安装教程
Pytorch implements the calculation of flops and params
Common questions and answering skills of project manager interview
Black apple server system installation tutorial, black apple installation tutorial, teach you how to install black apple in detail [easy to understand]
Qt和其它GUI库的对比
Installation and use of securecrtportable
QT QStringList用法
Big God explains open source buff gain strategy live broadcast
杰理之关于长按开机检测抬起问题【篇】
Openfire在使用MySQL数据库后的中文乱码问题解决
PM这样汇报工作,老板心甘情愿给你加薪
Lumiprobe蛋白质定量丨QuDye 蛋白定量试剂盒
北京大学ACM Problems 1005:I Think I Need a Houseboat
MySQL master-slave synchronization
Application of JDBC in performance test
基于开源流批一体数据同步引擎ChunJun数据还原—DDL解析模块的实战分享