vue通过后台返回的值来控制样式
2020-06-29 本文已影响0人
小程要谦虚
请先看效果图

我是通过后台给我返回代表颜色的数值比如1代表蓝色,2代表黄色等等
给它plate_num赋值为他数组正确的颜色位置比如liColor[0]代表绿色,liColor[1]代表蓝色
....来控制列表的颜色
首先在vue的data中定义一个数组
liColor:['green','blue','yellow']
<ul>
<li v-for="item in carNumberList" :key="item.id" :class="liColor[item.plate_color]">
<p>
<span class="plateNum">车牌号</span>
<span>{{item.plate_num}}</span>
</p>
<p>
<button class="logout" >注销</button>
</p>
</li>
</ul>