我需要一些帮助来尝试弄清楚如何为 v-bind:class 提供多个选项。我的 Uno 游戏在循环遍历您的卡片时,需要查看对象列表中的卡片颜色。([{ Color: green, Value: 6}]并确定卡片的文字颜色。这是我到目前为止所想出的:视图.jsgetClass: function(card){ var result = []; console.log(card); if (card.Color == "red"){ result.push('red'); }else if (card.Color == "green"){ result.push('green'); }else if (card.Color == "blue"){ result.push('blue'); }else if(card.Color == "yellow"){ result.push('yellow'); } console.log(result); return result; },超文本标记语言<ul id="myCards"> <button id="myCard" v-for="card in myCards" v-bind:class="getClass(card)" @click="playCard(card)"> {{card.Color}} {{card.Value}} </button></ul>CSSul{ text-align: left;}#myCards{ padding: none;}#myCard{ display: inline-block; height: 100px; width: 70px; border: 1px solid black; color: black; border: 2px solid black; border-radius: 6px; background-color: white; color: black; vertical-align: middle; margin: 5px;}.red{ color: red;}.green{ color: green;}.blue{ color: blue;}.yellow{ color: yellow;}
目前暂无任何回答
- 0 回答
- 0 关注
- 116 浏览
添加回答
举报
0/150
提交
取消