【问题标题】:how to dynamically setAttribute className in Vue's v-for loop?如何在 Vue 的 v-for 循环中动态设置属性类名?
【发布时间】:2023-01-08 19:39:21
【问题描述】:

我是 Vue.js 的新手。我的问题是: 我试试这个:

 <li v-for="(msg,index) in system_message" :class="index">

为了为每个 li 元素创建不同的类名,如 0、1、2、3。 但是 v-bind 不能以这种方式工作。类名保持为空。 我如何在 Vue 中使用 setAttribute 函数? 谢谢!

【问题讨论】:

    标签: vue.js


    【解决方案1】:

    不接受数字作为类名,您应该将索引与字符串连接起来,例如:

     <li v-for="(msg,index) in system_message" :class="`item${index}`">
    

    这给了你的item0, item1, item2 ...

    【讨论】:

      猜你喜欢
      • 2023-04-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-01
      • 2021-05-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多