码迷,mamicode.com
首页 > 其他好文 > 详细

[Vue @Component] Place Content in Components with Vue Slots

时间:2018-07-22 18:41:58      阅读:163      评论:0      收藏:0      [点我收藏+]

标签:can   style   elements   message   efi   when   and   mount   HERE   

Vue‘s slots enable you to define where content of a component should land when you define the content inside of a parent component. You can also name slots to arrange the elements however you‘d like and allow your component to build it‘s own content around the content that will be placed.

 

main.js:

import Vue from ‘vue‘
import App from ‘./App.vue‘


new Vue({
  render: (h) => (
    <App>
    <h1 slot="header">This is header</h1>  
    <h2 slot="footer">This is footer</h2>  
  </App>
  )
}).$mount(‘#app‘)

 

App.vue:

<template>
  <section class="section">
      <slot name=‘header‘></slot>

     <hello-world message="Message from APP"></hello-world>
  
     <slot name=‘footer‘></slot>
  </section>
</template>

 

[Vue @Component] Place Content in Components with Vue Slots

标签:can   style   elements   message   efi   when   and   mount   HERE   

原文地址:https://www.cnblogs.com/Answer1215/p/9350937.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!