【发布时间】:2019-02-02 01:14:00
【问题描述】:
我创建了一个全局组件,扩展了 Bootstrap Vue Table 组件,为每个名为 VTable 的表制作了一个自定义模板。
Bootstrap Vue Table 组件可以使用命名槽来自定义数据渲染。
<template>
<div>
<b-table
:items="items"
:fields="fields"
...
>
</b-table>
</div>
</template>
<script>
import Table from 'bootstrap-vue/es/components/table/table';
export default {
name: 'Vtable',
extends: Table,
...
};
</script>
我在另一个使用新的自定义 HTML 标记的表格组件中使用全局表格组件。
<v-table
v-if="items"
:items="items"
:fields="fields"
...
>
<template
slot="timestamp"
slot-scope="data"
>
...
</template>
<template
slot="row-details"
slot-scope="row"
>
...
</template>
</v-table>
问题是VTable组件中使用的命名槽没有显示在子组件内部。
我还尝试在全局组件中创建一个自定义命名槽
<template>
<div>
<b-table
...
>
<slot name="customRendering"/>
</b-table>
</div>
</template>
并像使用它
<v-table
...
>
<template slot="customRendering">
<template
slot="timestamp"
slot-scope="data"
>
...
</template>
<template
slot="row-details"
slot-scope="row"
>
...
</template>
</template>
</v-table>
没有成功
这可以简单地使用在孙子组件中定义的命名插槽,还是完全不可能?
我还想循环遍历customRendering 槽值以动态重新创建 Bootstrap Vue 表槽。
【问题讨论】:
标签: javascript vue.js vuejs2 vue-component