Javascript vuejs-将作用域模板向下传递到多个子级别
我正在用vue构建一个表,并使用插槽进行自定义格式设置。F.e.表格(是一个组件)使用一个Javascript vuejs-将作用域模板向下传递到多个子级别,javascript,vue.js,vuejs2,Javascript,Vue.js,Vuejs2,我正在用vue构建一个表,并使用插槽进行自定义格式设置。F.e.表格(是一个组件)使用一个thead-组件,其中每个th都是一个作用域/命名插槽。不过,为插槽指定模板只能从父级到子级(或者看起来-vm.$scopedSlots对于thead-组件是空的) 这是它的外形轮廓: // in index.html <my-table :data="data"> <template name="col1-header" props="column"> <th s
thead
-组件,其中每个th
都是一个作用域/命名插槽。不过,为插槽指定模板只能从父级到子级(或者看起来-vm.$scopedSlots
对于thead
-组件是空的)
这是它的外形轮廓:
// in index.html
<my-table :data="data">
<template name="col1-header" props="column">
<th style="colour: blue;">{{ column.name }}</th>
</template>
</my-table
// in my-table component
<template>
<table>
<my-thead :columns="columns">
</my-thead>
// tr: v-for over data
</table>
</template>
// in my-thead component
<template>
<thead>
<tr>
<slot :name="column.name + '-header'" :item="column" v-for="column in columns">
<th>{{ column.name }}</th>
</slot>
</tr>
</thead
</template>
//在index.html中
{{column.name}
我必须为这个问题创建一个解决方案。根据评论,有多种处理方法:
通过使用渲染函数(如下所示)并设置scopedSlot
属性,或通过使用属性传递scopedSlot
,将插槽传递给子级,如图所示。或者使用版本2.2.0中添加的提供/注入
机制来设置scopedSlots(我还没有尝试过)
render (h) {
return h('child', {
scopedSlots: this.$scopedSlots
})
}