当前位置:网站首页>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’
]"
边栏推荐
- 断点续传和下载原理分析
- Jerry's touch key recognition process [chapter]
- Go学习笔记
- AVL balanced binary tree (I) - concept and C language implementation
- 昨晚 Spark Summit 重要功能发布全在这里(附超清视频)
- SQL优化
- By analyzing more than 7million R & D needs, it is found that these eight programming languages are the most needed by the industry
- [ICLR 2021] semi supervised object detection: unbiased teacher for semi supervised object detection
- Great God detailed open source Buff gain Introduction 丨 Live
- Perl转换文件的编码类型
猜你喜欢

文件包含&条件竞争

PHP require/include 区别

Maya house modeling

分析超700万个研发需求发现,这八大编程语言才是行业最需要的

Implementation principle of PostgreSQL heap table storage engine

Solve the problems of Devops landing in complex environment with various tools with full stack and full function solutions

项目经理是领导吗?可以批评指责成员吗?

1、生成对抗网络入门

1. Introduction to generating countermeasures network

杰理之触摸按键识别流程【篇】
随机推荐
NLP paper lead reading | what about the degradation of text generation model? Simctg tells you the answer
Go learning notes
Wechat applet development practice cloud music
Jerry's determination of detection sensitivity level [chapter]
第299场
股票开户优惠链接,我如何才能得到?另外,手机开户安全么?
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
杰理之关于长按开机检测抬起问题【篇】
昨晚 Spark Summit 重要功能发布全在这里(附超清视频)
Summary of operating system interview questions (updated from time to time)
CADD course learning (1) -- basic knowledge of drug design
1045 error occurred in MySQL login. Modification method [easy to understand]
Common questions and answering skills of project manager interview
Lumiprobe无铜点击化学解决方案
[try to hack] windows system account security
QT QStringList用法
北京大学ACM Problems 1004:Financial Management
Jerry's touch key recognition process [chapter]
Static classes use @resource annotation injection
Halcon knowledge: check the measurement objects [1]