[英]How can I pass down slots to a grandchild component in Vue 3?
If I have a layout
component that contains a few slots, is it possible to have a component within layout
populate those slots?如果我有一个包含几个插槽的layout
组件,是否可以让layout
内的组件填充这些插槽?
<div id="app">
<layout>
<page></page>
</layout>
</div>
const app = Vue.createApp({});
app.component('layout', {
template: `
<header>
<slot name="header"></slot>
</header>
<main>
<slot name="main"></slot>
</main>
`,
});
app.component('page', {
template: `
<!--
is there a way fill each slot of "layout"? i.e.
<template #header>
<h1>Page Header</h1>
</template>
<template #main>
<h1>Page Content</h1>
</template>
-->
`,
});
app.mount('#app');
It seems what I'm looking for is being referred to as template blocks
in other places.看来我正在寻找的东西在其他地方被称为template blocks
。 This is not something Evan You (the creator of Vue) currently supports as he doesn't believe this functionality adds enough value for the added complexity.这不是 Evan You(Vue 的创建者)目前支持的东西,因为他认为此功能不会为增加的复杂性增加足够的价值。
Some interesting links:一些有趣的链接:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.