【问题标题】:How to apply class to a specific cell in a Buefy Table?如何将类应用于 Buefy 表中的特定单元格?
【发布时间】:2019-04-02 00:00:11
【问题描述】:

我想知道是否有一种方法可以动态应用针对 Buefy 表中特定单元格的类。例如,以下是我正在处理的代码:

模板:

  <b-table :data="status.peerStatus">
    <template slot-scope="props">
      <b-table-column :class="classObject" v-for="(column, index) in columns" :key="index"
        :label="column.label" :visible="column.visible" :width="200">
        {{ props.row[column.field] }}
      </b-table-column>
    </template>
  </b-table>

脚本:

  computed: {
    classObject() {
      return {
        "has-background-info": true
      };
    }

现在,由于 has-background-info 设置为 true,整行都以蓝色突出显示。

但是,我想做的是仅针对特定单元格并通过像这样传递单元格的值来有条件地应用类。

现在,我正在尝试像这样将单元格的值传递给classObject

&lt;b-table-column :class="classObject(props.row[column.field])" v-for="(column, index) in columns" :key="index"

并尝试相应地设置类

 computed: {
    classObject(cellValue) {
      return {
        "has-background-info": cellValue === "YES" ? true : false;
      };
    }

但是,上述方法不起作用。有没有其他方法可以做到这一点?

【问题讨论】:

    标签: vue.js buefy


    【解决方案1】:

    你应该把它放在method而不是computed

    methods: {
        classObject(cellValue) {
          return {
            "has-background-info": cellValue === "YES" ? true : false;
          };
        }
    }
    

    【讨论】:

    • 那行得通。非常感谢您的澄清!我知道这是一个菜鸟问题,但是为什么当我尝试使用 computed 而不是 methods 时它不起作用
    • computed组件的属性。但是在你的组件中,这个类的值对于每个单元格是不同的,所以应该在方法中动态计算。
    • 再次感谢您的澄清!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-05-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-21
    • 2020-01-24
    • 2018-11-21
    相关资源
    最近更新 更多