当前位置:网站首页>在循环中动态改变标签元素的样式
在循环中动态改变标签元素的样式
2022-06-22 17:18:00 【旋转飘飘】
利用循环v-for在页面上放置标签元素
<div v-for=(item,index) in list :key="index">{
{item}}/div>
list=[
'red','yellow','green','blue'
]
设置不同的类样式
.red{
color:red}
.yellow{
color:yellow}
.green{
color:green}
.blue{
color:blue}
定义对象来绑定索引(或其他项,看需要决定)与类样式的关系
const colorEnum={
red:{
class:'red'},
yellow:{
class:'yellow'},
green:{
class:'green'},
blue:{
class:'blue'},
}
修改标签中类样式
<div v-for=(item,index) in list :key="index" :class="$$(colorEnum, [item], 'class')" >{
{item}}/div>
效果查看

代码说明
说明:代码写在vue框架中
关键句 :class="$$(colorEnum, [item], 'class')" //加两个$来动态匹配item和colorEnum中相对应对象中的键class的值。
边栏推荐
- [OWT] OWT client native P2P E2E test vs2017 build
- Excuse me, when cdc2.0 reads mysql, there should be no table lock. An error was just reported, access D
- 详解openGauss多线程架构启动过程
- Zero basic programming / reverse learning / over detection (Frida practice)
- Typescript (7) generic
- Short video live broadcast source code, use of EditText input box
- Beijing restorer's half moon: how to rekindle the fireworks in store management
- 项目经理们在哪个时刻特别想逃离工作?
- 各位大佬,第一次使用flink mysql cdc, 现在程序启动 没报错 新增数据没有打印出来
- Q: how bad can a programmer be?
猜你喜欢

The Fourth Youth Life Science Forum | first round notice

Correct method of converting Inkscape into DXF file SVG exporting DXF file

云端极简部署Svelte3聊天室

Grafana 9 is officially released, which is easier to use and more cool!

Nuxt - create nuxt app

UE4_UE5制作3DUI-跟随相机朝向(附工程)

Nuxt - Universal (SSR / SSG) / single page app (rendering mode)

Binary tree practice the second bullet

The world's first AR contact lens, the entrance of metauniverse is really opened this time?

A course for New Oriental transformation bilingual live broadcast to bring goods to the project manager
随机推荐
Short video live broadcast source code, use of EditText input box
SystemVerilog(十二)-$unit声明空间
利用Inkscape转换为dxf文件的正确方法 svg导出dxf文件
UE4_UE5制作3DUI-跟随相机朝向(附工程)
Oculus学习笔记之控制器输入初步(一)
Pytorch——报错解决:“torch/optim/adamw.py” beta1, UnboundLocalError: local variable ‘beta1‘
Does CDC 2.2.1 monitoring sqlserver not support monitoring multiple databases?
Array implementation of circular linked list
What is the experience of writing a best seller
知乎热问:一个程序员的水平能差到什么程度?
平安证券开户安全吗?它和平安银行是什么关系呢?
docker: Error response from daemon: Conflict. The container name “/mysql“ is already in use by conta
Source code of live video system, hiding and Title Modification of the top title bar
docker: Error response from daemon: Conflict. The container name “/mysql“ is already in use by conta
When online and offline integration accelerates and information docking channels are diversified, the traditional center will not be necessary
Missing value handling
The Jenkins container failed to install the ruby runtime plug-in. Solve the error
SaaS application development guide
azkaban启动报错 2022/06/20 21:39:27.726 +0800 ERROR [StdOutErrRedirect] [Azkaban] Exception in thread “m
腾讯云国际版云服务器欠费说明