HLJ 发布于
2021-08-20 14:43:10

一段 vue computed计算属性控制样式代码

<div>
  <template v-for="item in 10">
    <li :style="setItem(item).attr">{{setItem(item).value}}</li> </template>
</div>

computed:{
  setItem(){
    return (item) => {
      const newItem = {};
            newItem.attr = item == 1?'background:violet':
            newItem.attr = item == 2?'background:yellowgreen':
            newItem.attr = item == 3?'background:blue':
            newItem.attr = item == 4?'background:coral':
            newItem.attr = item == 5?'background:deepskyblue':'background:gold';

            newItem.value = item == 1?'background:violet':
            newItem.value = item == 2?'background:yellowgreen':
            newItem.value = item == 3?'background:blue':
            newItem.value = item == 4?'background:coral':
            newItem.value = item == 5?'background:deepskyblue':'background:gold';
                
            return newItem
    }
  }
}
当前文章内容为原创转载请注明出处:http://www.good1230.com/detail/2021-08-20/561.html
最后生成于 2023-06-27 21:37:54
此内容有帮助 ?
0