VuePress implements a content distribution API for Markdown. With this feature, you can split your document into fragments, allowing flexible composition in the layout component.
- Vue Slot Event
- Vue Slot Props Online
- Vue Slot Pass Props
- Vue Get Slot Props
- Vue Slots Vs Props
- Vue Scope Slot
- Vue Slot Component Props
我们观察一个 Vue 组件主要观察三点:props、event 以及 slots。对于 BaseComponent 组件而言,它接收一个数字类型的 props 即 test,并发射一个自定义事件,事件的名称是:customize-click,没有 slots。我们会这样使用该组件:. Vue Select leverages scoped slots to allow for total customization of the presentation layer. Slots can be used to change the look and feel of the UI, or to simply swap out text. # footer 3.8.0+ Displayed at the bottom of the component. ← Props Events →.
# Why do I need Markdown Slot?
First, let’s review the relationship between layout components and Markdown files:
Markdown files are providers of metadata (page content, configuration, etc.), while layout components consume them. We can use
frontmatter
to define some metadata for common data types, but frontmatter
is hard to do something about Markdown / HTML, a complex metadata that involves differences before and after compilation.Markdown Slots solve this problem.
# Named Slots
You can define a named Markdown slot through the following Markdown syntax:
Use the
Content
component to use the slot in the layout component:TIP
Here we are using
slot-key
instead of slot
, because in Vue, slot
is a reserved prop name.# Default Slot Content
By default, the slot-free part of a Markdown file becomes the default content of a Markdown slot. You can access this directly using the
Content
component:# Example
Suppose your layout component is as follows:
If the Markdown content of a page is this:
Vue Slot Event
Then the rendered HTML of this page will be:
Note that:
- Unlike the slot mechanism provided by Vue(opens new window) itself, each content distribution is wrapped in a
div
whose class iscontent
with the name of the slot. - You need to ensure the uniqueness of the slot defined.
VuePress implements a content distribution API for Markdown. With this feature, you can split your document into fragments, allowing flexible composition in the layout component.
# Why do I need Markdown Slot?
Vue Slot Props Online
First, let’s review the relationship between layout components and Markdown files:
Markdown files are providers of metadata (page content, configuration, etc.), while layout components consume them. We can use
frontmatter
to define some metadata for common data types, but frontmatter
is hard to do something about Markdown / HTML, a complex metadata that involves differences before and after compilation.Markdown Slots solve this problem.
# Named Slots
You can define a named Markdown slot through the following Markdown syntax:
Use the
Content
component to use the slot in the layout component:TIP
Here we are using
slot-key
instead of slot
, because in Vue, slot
is a reserved prop name.Vue Slot Pass Props
# Default Slot Content
Vue Get Slot Props
By default, the slot-free part of a Markdown file becomes the default content of a Markdown slot. You can access this directly using the
Content
component:# Example
Suppose your layout component is as follows:
Vue Slots Vs Props
If the Markdown content of a page is this:
Vue Scope Slot
Then the rendered HTML of this page will be:
Vue Slot Component Props
Note that:
- Unlike the slot mechanism provided by Vue(opens new window) itself, each content distribution is wrapped in a
div
whose class iscontent
with the name of the slot. - You need to ensure the uniqueness of the slot defined.