Slots — Vue.js | vue js content
![Slots — Vue.js](https://i.imgur.com/axBPWDg.jpg)
ThispageassumesyouvealreadyreadtheComponentsBasics[1].Readthatfirstifyouarenewtocomponents.SlotContentandOutlet[2]Wehavelearnedthatcomponentscanacceptprops,whichcanbeJavaScriptvaluesofanytype.Buthowabouttemplatecontent?Insomecases,wemaywanttopassatemplatefragmenttoachildcomponent,andletthechildcomponentrenderthefragmentwithinitsowntemplate.Forexample,wemayhavea
![Slots — Vue.js](http://pix4.agoda.net/hotelimages/agoda-homes/5899847/61e1a790eeb181e40e8f262ea5a396dc.jpg?s=800x)
This page assumes youve already read the Components Basics[1]. Read that first if you are new to components.
Slot Content and Outlet [2]We have learned that components can accept props, which can be JavaScript values of any type. But how about template content? In some cases, we may want to pass a template fragment to a child component, and let the child component render the fragment within its own template.
For example, we may have a <FancyButton> component that supports usage like this:
template<FancyButton> Click me! <!-- slot content --> </FancyButton>The template of <FancyButton> looks like this:
template<button class="fancy-btn"> <slot></slot> <!-- slot outlet --> </button>The <slot> element is a slot outlet that indicates where the parent-provided slot content should be rendered.
And the final rendered DOM:
html<button class="fancy-btn">Click me!</button>...取得本站獨家住宿推薦 15%OFF 訂房優惠
本站住宿推薦 20%OFF 訂房優惠,親子優惠,住宿折扣,限時回饋,平日促銷
Components Basics — Vue.js | vue js content
Slots — Vue.js | vue js content
Template Syntax — Vue.js | vue js content
「Vue.js 學習筆記Day15」 | vue js content
Vue學習筆記— 初探Vue.js(六). 接續上篇,昨天經朋友推薦發現 ... | vue js content
中篇介紹Vue檔案結構 | vue js content
一起幫忙解決難題,拯救IT 人的一天 | vue js content
25 Vue組件- 動態切換 | vue js content
04 Vue的模板語法- v-text, v-html | vue js content
Components Basics | vue js content
Components Basics | vue js content
Template Syntax | vue js content
Slots | vue js content
Built | vue js content
Options | vue js content
Introduction | vue js content
Vue.js | vue js content
2 | vue js content
04 Vue的模板語法- v-text, v | vue js content
![](https://i.imgur.com/axBPWDg.jpg)