# table修改移除单元格数据源颜色

An image An image

onInit() {

      //如果所有表格的数据源都不需要背景颜色,配置main.js中useTag属性为false(配置后,下面的代码就不用了)

      this.columns.forEach(x => {
        // if (x.field == "Variety") {
           //设置table有数据源的列为正常显示(不显示背景颜色)
        //   x.normal = true;
        // }
        if (x.field == "Province") {
          //设置table有数据源的列为正常显示(并设置自定义文字颜色)
          x.normal = true;
          //根据不同的值,定义不同的样式(如:文字颜色)
          x.getStyle = (row, column) => {
            if (row.Province == "130000") {
              return { color: "red", cursor: "pointer" };
            }
            return { color: "blue", cursor: "pointer" };
          };
          //绑定点击事件
          x.click = (row, column, event) => {
            this.$message.info(row.City);
          };
        }
      });

}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27