vue $refs给for循环出来的某一个添加样式

<ul class="q-main-u">
  <li v-for="(subitem,subindex) in quectionList" ref="list" :key="subindex">
    <span>{{subitem.text}}</span>
  </li>
</ul>

  以上,是for循环渲染出来的一个列表,给li添加ref,

在需要给具体的某一个添加样式的时候可以这样写 

this.$refs.list[i].style.backgroundColor="rgba(214,37,80,.5)"

  其中this.$refs.list为查询到的所有的li,

  this.$refs.list[i],根据索引找到其中需要的某一个li,

  给这个li添加一个背景颜色,必须写成backgroundColor,不能写background-color形式;

  背景色是可以使用rgba()形式的;

 

添加其他样式也是同样的写法。

 

的的

的的的

。。。。。。

 

posted @ 2020-08-13 12:14  烂笔头~  Views(3530)  Comments(0Edit  收藏  举报