【发布时间】:2018-12-05 00:30:41
【问题描述】:
我想为带有自定义数据呈现(模板)的 bootstrap-vue 表创建一个父组件。
现在,有点像这样:
<b-table
:items="result"
:fields="fields"
:current-page="currentPage"
:per-page="perPage">
<template slot="Index" slot-scope="data">
{{ data.index + 1 }}
</template>
<!-- more templates for various columns here -->
</b-table>
<b-pagination
align="center"
:total-rows="result.length"
v-model="currentPage"
:per-page="perPage"
/>
我想将它包装在一个组件中的原因是因为我多次使用这个表格布局,包括分页及其所有属性(如条纹、边框等)。
唯一改变的是列模板。
我知道,Vue 的做法是创建一个类似<slot name="x"></slot> 的槽并用<template slot="x">...</template> 填充它。一方面,这与 bootstrap-vue template 一致,另一方面,bootstrap-vue 似乎只能正确呈现模板,前提是它们正好放置在 b-table 内。
基本上,我想要实现的是这样一个组件:
<b-table>
<slot name="templates"/>
</b-table>
<b-pagination stuff.../>
并在这样的子组件中使用它:
<TemplateTable>
<template slot="templates">
<template slot="Index" slot-scope="data">
{{ data.index + 1 }}
</template>
<!-- more templates -->
</template>
</TableTemplate>
有没有人做过类似的事情并想出了解决办法?
【问题讨论】:
标签: vue.js vuejs2 vue-component bootstrap-vue