vue.js - 设置 Vue Bootstrap Table _rowVariant 和行边距
问题描述
我需要一些想法来定制我的 Vue Boostrap 表。
我有一些数据,例如:
const tasks = [
{
title: 'title 1',
wbs: '0',
description: '...'
},
{
title: 'title 2',
wbs: '1',
description: '...'
},
{
title: 'title 3',
wbs: '1.1',
description: '...'
},
{
title: 'title 4',
wbs: '1.1.1',
description: '...'
},
{
title: 'title 5',
wbs: '1.2',
description: '...'
}
]
我的桌子:
<b-table
striped
hover
isRowHeader
:responsive="'md'"
:items="tasks"
:fields="fields"
:per-page="perPage"
:current-page="currentPage"
/>
结束我的任务是从商店计算的:
computed: { ...mapGetters({ tasks: "getTasks" }) }
我需要根据 WBS 值自定义表格。将 _rowVariant 设置为 0 和 1 的“信息”,将“警告”设置为 1.1 和 1.2,将“危险”设置为其他人。并且还根据 WBS 大小在标题左侧添加合并。请给出一些想法来实现这一点。提前泰。
解决方案
我认为使用该tbody-tr-class
属性是解决您问题的好方法。在我看来,使用 的特性b-vue
比使用其他方法增加代码的复杂性更好。
您可以查看此代码段以获取一个简单的示例:
new Vue({
el: '#app',
data() {
return {
fields: [{
key: "title",
},
{
key: "wbs",
"tbody-tr-class": (type, key, item) => {
return 'text-danger'
}
},
{
key: "description",
}
],
items: [{
title: 'title 1',
wbs: '0',
description: '...'
},
{
title: 'title 2',
wbs: '1',
description: '...'
},
{
title: 'title 3',
wbs: '1.1',
description: '...'
},
{
title: 'title 4',
wbs: '1.1.1',
description: '...'
},
{
title: 'title 5',
wbs: '1.2',
description: '...'
}
]
}
},
methods: {
rowClass(item, type) {
if (item.wbs < 1.1) {
return "table-info"
} else if (item.wbs < 1.2) {
return "table-warning"
} else {
return "table-danger"
}
}
}
})
<link type="text/css" rel="stylesheet" href="https://unpkg.com/bootstrap@4.5.3/dist/css/bootstrap.min.css" />
<link type="text/css" rel="stylesheet" href="https://unpkg.com/bootstrap-vue@2.21.2/dist/bootstrap-vue.css" />
<script src="https://unpkg.com/vue@2.6.12/dist/vue.min.js"></script>
<script src="https://unpkg.com/bootstrap-vue@2.21.2/dist/bootstrap-vue.min.js"></script>
<div id="app">
<b-table hover :items="items" :tbody-tr-class="rowClass"></b-table>
</div>
推荐阅读
- c# - WebClient 未遵循 .Net Core 3.1 中的重定向
- javascript - ajax 向 PHP 提交错误的数据
- python-3.x - Qt:在包含子布局的 QFormLayout 中显示或隐藏行
- java - 如何使用 spring-data 检索 mongodb 集合?
- django - 使用 PyCharm 创建 Django 项目时出错
- javascript - 无法在反应组件中使用 postMessage
- azure-functions - 如何编写一个 CosmosDBTrigger 来更新已更改的同一文档?
- python - 编写代码对多个 pandas DataFrames 执行相同的操作
- python - 发送嵌入 discord.py 后收听反应或消息
- javascript - 我想要一个按钮单击以将 html 标记添加到我的表单