父组件 : <template> <nav-bar> <template #left> <button>{{ leftText }}</button> </template> <template #center> <span>内容</span> </template> <template v-slot:right> <a href="#">登录</a> </template> </nav-bar> </template> <script> import NavBar from './NavBar.vue' export default { components: { NavBar }, data() { return { leftText: "返回" } } } </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>
标签:vue,NavBar,插槽,具名,leftText,组件 From: https://www.cnblogs.com/qd-lbxx/p/16612701.html