From 6cff45fe7d5cbb1427e940355a3e7dd0befe192e Mon Sep 17 00:00:00 2001 From: Jinjiang Date: Tue, 10 Apr 2018 10:02:24 +0800 Subject: [PATCH 1/3] added components-slots.md --- src/v2/guide/components-slots.md | 229 +++++++++++++++++++++++++++++++ 1 file changed, 229 insertions(+) create mode 100644 src/v2/guide/components-slots.md diff --git a/src/v2/guide/components-slots.md b/src/v2/guide/components-slots.md new file mode 100644 index 000000000..f90cf8e6e --- /dev/null +++ b/src/v2/guide/components-slots.md @@ -0,0 +1,229 @@ +--- +title: Slots +type: guide +order: 104 +--- + +> This page assumes you've already read the [Components Basics](components.html). Read that first if you are new to components. + +## Slot Content + +Vue implements a content distribution API that's modeled after the current [Web Components spec draft](https://github.com/w3c/webcomponents/blob/gh-pages/proposals/Slots-Proposal.md), using the `` element to serve as distribution outlets for content. + +This allows you to compose components like this: + +``` html + + Your Profile + +``` + +Then in the template for ``, you might have: + +``` html + + + +``` + +When the component renders, the `` element will be replaced by "Your Profile". Slots can contain any template code, including HTML: + +``` html + + + + Your Profile + +``` + +Or even other components: + +``` html + + + + Your Profile + +``` + +If `` did **not** contain a `` element, any content passed to it would simply be discarded. + +## Named Slots + +There are times when it's useful to have multiple slots. For example, in a hypothetical `base-layout` component with the following template: + +``` html +
+
+ +
+
+ +
+
+ +
+
+``` + +For these cases, the `` element has a special attribute, `name`, which can be used to define additional slots: + +``` html +
+
+ +
+
+ +
+
+ +
+
+``` + +To provide content to named slots, we can use the `slot` attribute on a `