首页 > 其他分享 >具名插槽-动态传入数据

具名插槽-动态传入数据

时间:2022-08-22 14:48:38浏览次数:87  
标签:center 传入 NavBar 插槽 具名 组件

父组件 : 

<template>
  <!-- nav-bar只给一个插槽动态传入数据 -->
  <nav-bar>
    <template v-slot:[position]>
      <a href="#">注册</a>
    </template>
  </nav-bar>
  <button @click=" position = 'left' ">左边</button>
  <button @click=" position = 'center' ">中间</button>
  <button @click=" position = 'right' ">右边</button>
</template>

<script>
  import NavBar from './NavBar.vue'

  export default {
    components: {
      NavBar
    },
    data() {
      return {
        position: "center",
      }
    }
  }
</script>

<style scoped>
</style>
子组件 : 

<template> <div class="nav-bar"> <div class="left"> <slot name="left">left</slot> </div> <div class="center"> <slot name="center">center</slot> </div> <div class="right"> <slot name="right">right</slot> </div> </div> </template>

 

标签:center,传入,NavBar,插槽,具名,组件
From: https://www.cnblogs.com/qd-lbxx/p/16612719.html

相关文章