无法在另一个组件中渲染$ children

时间:2019-07-09 21:23:27

标签: vue.js

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

主要:

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

Foo:

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

1 个答案:

答案 0 :(得分:3)

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

相关问题