Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vue.js/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript vuejs-将作用域模板向下传递到多个子级别_Javascript_Vue.js_Vuejs2 - Fatal编程技术网

Javascript vuejs-将作用域模板向下传递到多个子级别

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

我正在用vue构建一个表,并使用插槽进行自定义格式设置。F.e.表格(是一个组件)使用一个
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
  })
}