【发布时间】:2020-08-27 21:07:29
【问题描述】:
从 Bootstrap Vue 表格文档中,可以自定义呈现数据。
https://bootstrap-vue.org/docs/components/table#scoped-field-slots
示例显示以下模板:
<template v-slot:cell(index)="data">
{{ data.index + 1 }}
</template>
我使用 PUG 作为模板语言,但它的语法有些问题。我没有找到将上述示例“翻译”为 PUG 语法的正确方法。
由于冒号,这不起作用:
template(v-slot:cell(index)="data") {{ data.index + 1 }}
这似乎也不正确:
template(v-slot(cell(index)="data")) {{ data.index + 1 }}
更新 #1
这是我的字段定义:
fields: [
"index",
{
key: "name",
label: this.$t("document.name"),
sortable: true
}
]
这是模板:
b-table#filesList(
v-if="list.length > 0"
:items="list"
:fields="fields"
stacked="md"
striped
responsive
)
template(v-slot:cell(index)="data") {{ data.index + 1 }}
这仅显示一个空的“索引”列。如果我将模板更改为已弃用的 slot 和 slot-scope 同步税,它就可以工作:
template(slot="index" slot-scope="data") {{ data.index + 1 }}
【问题讨论】:
-
您是否将
index字段添加到您的字段数组中? -
@hiws 是的,
index字段已添加。 -
您使用的是 Bootstrap-Vue 版本
2.0.0-rc.x吗?它的语法与当前版本的表槽不同。v-slot也需要 vuev2.6.x,所以确保你已经安装了。 -
我们正在使用
"bootstrap-vue": "^2.0.0-rc.20","vue": "^2.6.6" -
你是对的。谢谢!我在本地升级到 Bootstrap Vue 2.14.0,现在它可以正常工作了 :-)
标签: vue.js pug bootstrap-vue