Vue Slots


子组件vue

<template>
  <div>
    <slot v-if="slots.header" name="header"></slot>
    <slot></slot>
    <slot name="footer"></slot>
  </div>
</template>

<script>
export default {
  mounted() {
    console.log(this.$slots, '$slots')
  },
  computed: {
    slots() {
      return this.$slots
    }
  }
}
</script>

父组件vue

<template>
  <div class="test">
    <test>
      <div slot="header">slot: header</div>
      <div slot="header">slot: header</div>
      <div>slot default</div>
      <div slot="footer">slot: footer</div>
    </test>
  </div>
</template>

<script>
import Test from './test'
export default {
  components: { Test },
}
</script>


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM