【问题标题】:Vue 2.6.0 - How to use the new slot syntax to render slot content to children component's named slotVue 2.6.0 - 如何使用新的插槽语法将插槽内容呈现到子组件的命名插槽
【发布时间】:2019-02-07 13:27:32
【问题描述】:

要理解我的问题,请查看以下伪代码:

<my-tooltip-wrapper>
  <some-slot-content />
</my-tooltip-wrapper

MyTooltipWrapper 包含来自包的TooltipComponent。但是,这需要另一个插槽来显示我的&lt;some-slot-content /&gt;

要查看使用旧语法的this as an example,请查看并尝试使用新语法。

在插槽语法更改之前,我可以像这样使用它:

//inside of MyTooltipWrapper
<tooltip-component>
   <slot
      name="reference"
      slot="reference"
   />
</tooltip-component>

但是,您将如何将其更改为新语法?我试过了,但没有用:

<template #reference>
  <slot
    name="reference"
  />
</template>

【问题讨论】:

  • 我看到了你的例子,它正在工作。
  • @roliroli 抱歉造成误会,本例使用旧语法,请尝试使用新语法...
  • 我认为该错误已通过以下方式修复:github.com/vuejs/vue/commit/…

标签: vue.js


【解决方案1】:

https://jsfiddle.net/a8q09cfh/

<slot-owner>
  <template v-slot:reference>
      Hello world
  </template>
</slot-owner>


Vue.component('slot-owner', {
  template: `
     <div>
        <slot name="reference" />
     </div>
  `
});

【讨论】:

  • 你能用我的小提琴吗,因为你的回答根本没有帮助......
  • element-ui 还不支持 vue-2.6 插槽语法:github.com/ElemeFE/element/issues/14309
  • 这很奇怪,因为我认为这对我来说并不重要,因为我不需要在元素中渲染某些东西。我只需要将插槽“重定向”到元素插槽...
【解决方案2】:

有人问过类似问题here

它已被最新的commit修复

【讨论】:

    猜你喜欢
    • 2021-02-06
    • 2018-08-05
    • 2019-06-08
    • 1970-01-01
    • 2018-11-05
    • 1970-01-01
    • 1970-01-01
    • 2021-01-15
    • 2018-09-14
    相关资源
    最近更新 更多