vue可以通过父组件的prop注入组件定义吗?

template:`<div data-child1></div>`
template:`<div data-child2></div>`

parent

template:
`<div>
    <child1></child1>
    <child2></child2>
</div>`

app

template:`<parent components="components"></parent>`
components:{
    child1
    child2
}
阅读 3k
2 个回答

你该用slot吧

parent - template :
<div>
  <slot name="child1"></slot>
  <slot name="child2"></slot>
</div>


APP 定义时
<parent>
   <div slot="child1"></div>
   <div slot="child2"></div> 
</parent>

使用slot 可以这样动态替换内容。如果动态组件的话 可以通过props 传值到子组件渲染.  
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题