当前位置:网站首页>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’
]"
边栏推荐
- GeoServer installation
- The Commission is so high that everyone can participate in the new programmer's partner plan
- 信息学奥赛一本通 1362:家庭问题(family)
- Is the project manager a leader? Can you criticize and blame members?
- Web主机iptables防火墙安全脚本
- [iccv 2019] characteristics precise supervision of feature super resolution for small object detection
- What are database OLAP and OLTP? Same and different? Applicable scenarios
- Common questions and answering skills of project manager interview
- Go 语言标识符、包名规范
- Solve the problems of Devops landing in complex environment with various tools with full stack and full function solutions
猜你喜欢

To eliminate bugs, developers must know several bug exploration and testing artifacts.

哈夫曼树(一)基本概念与C语言实现

文件包含&条件竞争

昨晚 Spark Summit 重要功能发布全在这里(附超清视频)
![[1175. prime number arrangement]](/img/f2/d427db03da151786ea1dfb7a76328a.png)
[1175. prime number arrangement]

Big God explains open source buff gain strategy live broadcast

STL的基本组成部分

DEX file parsing - Method_ IDS resolution

1. Introduction to generating countermeasures network

Evolution of screen display technology
随机推荐
Heartbeat and DRBD configuration process
Lumiprobe染料酰肼丨BDP FL 酰肼方案
北京大学ACM Problems 1001:Exponentiation
Pytorch implements the calculation of flops and params
C文件指针
SQL优化
Exness: the final value of US GDP unexpectedly accelerated to shrink by 1.6%
[iccv 2019] characteristics precise supervision of feature super resolution for small object detection
By analyzing more than 7million R & D needs, it is found that these eight programming languages are the most needed by the industry
mysql登录出现1045错误修改方法[通俗易懂]
【Try to Hack】Windows系统账户安全
Taihu Lake "China's healthy agricultural products · mobile phone live broadcast" enters Taihu Lake
Jerry's touch key recognition process [chapter]
Client request external interface standard processing method
项目经理面试常见问题及回答技巧
Jerry's long press reset [chapter]
Summary of operating system interview questions (updated from time to time)
exness:流动性系列-流动性清洗和反转、决策区间
DEX文件解析 - method_ids解析
Web host iptables firewall security script