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

Posted answer1215

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[Vue @Component] Place Content in Components with Vue Slots相关的知识,希望对你有一定的参考价值。

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的主要内容,如果未能解决你的问题,请参考以下文章

Vue&Laravel:访问和使用eventHub

Unknown custom element: <el-container> - did you register the component correctly? For recursive co(

vue路由传参

Vue、Axios 和 Google Maps Place API CORS 错误 [重复]

vue组建的创建

Vue.js——6.创建组件