【发布时间】:2019-11-25 09:09:21
【问题描述】:
我正在尝试使用 Vuejs 实现这样的目标 Color coded list of client
这是我的 vue 代码的样子
<div class="list-group-item" data-toggle="sidebar" data-sidebar="show" v-for="(client, index) in clients" :key="client.id">
<a href="#" class="stretched-link"></a>
<div class="list-group-item-figure">
<div class="tile tile-circle" :class="getBgColor(++index)"> {{ client.name.charAt(0) }} </div>
</div>
<div class="list-group-item-body">
<h4 class="list-group-item-title"> {{ client.name }} </h4>
<p class="list-group-item-text"> {{ client.city }}, {{ client.country }} </p>
</div>
</div>
这是我的脚本,我有我想用来获取适当的 css 类的开关盒
getBgColor(color) {
let bg_color = 'bg-blue';
switch(color) {
case 1:
bg_color = 'bg-blue'
break;
case 2:
bg_color = 'bg-indigo'
break;
case 3:
bg_color = 'bg-purple'
break;
case 4:
bg_color = 'bg-pink'
break;
case 5:
bg_color = 'bg-red'
break;
case 6:
bg_color = 'bg-orange'
break;
case 7:
bg_color = 'bg-yellow'
break;
case 8:
bg_color = 'bg-green'
break;
case 9:
bg_color = 'bg-cyan'
break;
default:
bg_color = ''
}
this.colorCode++
return bg_color
}
},
【问题讨论】:
-
当单独的索引应该起作用时,你为什么要写 $index ? getBgColor(index) 一个人应该在这里完成工作,你试过了吗?
-
@Jake - 我同意这也可以工作......但这不是我的问题,问题是如何将课程设置为 1-9 并重新启动(蓝色到青色,然后回到蓝色.. .青色)。有什么想法???
-
我要做的是定义一个带有修饰符的全局类:bg-color--1, bg-color--2, bg-color--3, bg-color--4等,然后在循环中将它们设置为 :class="bg-color--' + index" :)
-
拥有一个数组
bg_color=['bg-cyan','bg-green' ...]怎么样,你可以从函数中传递索引。将索引存储在 vuejs 数据变量中。用索引更新它只要跟踪bg_color的长度如果索引大于`(索引> bg_color.length -1)将数据变量重置为索引开始
标签: css class vuejs2 laravel-6.2