javascript - Bootstrap Vue更改b表中每个单元格的背景
问题描述
我正在使用 bootstrap vue b-table 来显示我的项目:
<b-table striped bordered :tbody-tr-class="row_class" :fields="fields" :items="items" head-variant="light" class="o-list"
thead-class="o-gradient-header"
@row-selected="onRowSelected" selectable
no-local-sorting @sort-changed="change_sort" :sort-by="list_options.sort"
:sort-desc="list_options.order==='desc'">
...
</b-table>
我想根据函数调用更改每个单元格的背景颜色:
row_class(item) {
// Insert conditionals
// return CSS class string
}
但这正在改变整个行的样式。我不想要那个。我只想更改单元格的样式?有没有办法改变每个单元格的背景颜色?
解决方案
tbody-tr-class
您可以使用道具设置每一行的样式
<b-table striped hover caption-top
:items="items"
:fields="fields"
:tbody-tr-class="rowClass"
>
</b-table>
脚本
new Vue({
el: "#app",
data() {
return {
fields: [
{
key: "name",
label: "Name",
sortable: true
},
{
key: "email",
label: "Email",
sortable: true
},
{
key: "age",
label: "Old",
sortable: true
}
],
items: [
{ age: 40, name: "admin1", email: "hoge@for.jp" },
{ age: 21, name: "admin2", email: "huga@for.jp" },
{ age: 89, name: "admin3", email: "piyo@for.jp" },
{ age: 38, name: "admin4", email: "aaaaa@for.jp" }
]
};
},
methods: {
rowClass(item, type) {
if (!item || type !== 'row') return
if (item.age > 30) return 'table-success'
}
}
});
推荐阅读
- python - python 3.7.0 乌龟不起作用
- mysql - 根据另一个表列以 DESC 顺序对 MySQL 查询结果进行排序
- c# - 仅访问模型时的 ASP.NET Core NullReferenceException
- django - PermissionError [Errno 13] 权限被拒绝:'After.png'
- jvm - 如何分析大型 jvm 转储文件
- r - R包tabulizer错误
- python - 如何使用 docker-py 创建带有接口终端的守护程序容器?
- jquery - 弹出框内的jquery引导选择器
- ruby-on-rails - 为什么 EC2 服务器上的多个 Ruby 进程会导致 100% 的 CPU 利用率?
- reactjs - TypeScript 和 React 问题