search

Home  >  Q&A  >  body text

javascript - How to add styles to vue elements

The main problem is: I remembered that I could $indexpass an index and it would be easy to handle. How do I know which row of data is currently being rendered by tr? How to use computedDo

I want to change the text color

My code:

大家讲道理大家讲道理2750 days ago808

reply all(3)I'll reply

  • 高洛峰

    高洛峰2017-05-16 13:47:12

    Write the style and then bind it dynamically: class ="{green:true,red:false....}"

    reply
    0
  • 过去多啦不再A梦

    过去多啦不再A梦2017-05-16 13:47:12

    You are using the element-ui framework, add class in el-table里有这么一个属性row-class-name,是一个回调函数,可以给table-cell. For details, you can check out the official website, at the bottom.
    For example: (display different background colors by judging the value in a row of data)
    template

    <el-table :data="roleMenuTable" border style="width: 100%" :row-class-name="tableRowClassName">

    script

    methods: {
        // 已选择渲染样式
        tableRowClassName (row, index) {
          if (row.operation) {
            return 'info-row'
          } else {
            return ''
          }
        }
        }

    style

    <style>
    .el-table .info-row{
      background: #5CB85C;
    }
    </style>

    Effect:

    reply
    0
  • 滿天的星座

    滿天的星座2017-05-16 13:47:12

    现在也可以啊,把v-for改成v-for="(item, index) in lists",inde就是索引了

    reply
    0
  • Cancelreply