【问题标题】:Cannot Render $children in Another Component无法在另一个组件中渲染 $children
【发布时间】:2019-11-19 11:44:56
【问题描述】:

我想要动态内容,所以我尝试了类似下面的内容。当我登录$children[0] 时,我得到了正确的数据,但 HTML 上没有显示任何内容。有没有办法渲染$children

主要:

<template>
   <foo>
      <h1>Content should be rendered {{number}} time.</h1>
   </foo>
</template>
<script>
components: { Foo },
data() {
  return {
    number: 1
  }
}
...
</script>

富:

<template>
   <div v-html="$children[0]"></div>
</template>

【问题讨论】:

标签: vue.js


【解决方案1】:

您需要使用Slot。只需将&lt;div v-html="$children[0]"&gt;&lt;/div&gt; 替换为&lt;slot&gt;&lt;/slot&gt;

【讨论】:

    猜你喜欢
    • 2018-12-12
    • 2020-10-21
    • 2021-12-04
    • 1970-01-01
    • 2018-01-26
    • 1970-01-01
    • 1970-01-01
    • 2021-08-18
    • 1970-01-01
    相关资源
    最近更新 更多