vue中v-slot使用


vue中v-slot使用

 

1,v-slot的使用步驟

  

  

<!-- slot.vue-->

  <!-- 通過name屬性指定具名插槽,沒有name屬性的為默認插槽-->
 <slot name="header">我是header</slot>

 <slot name="main">我是main</slot>

 <slot :title="title" name="footer"></slot>

 <slot></slot>



// index.vue

<!-- 通過v-slot:footer="title"來拿到slot頁面傳過來的數據,v-slot:xxx來指定對應slot.vue中的插槽-->

<slot-name>
            <template v-slot:header>我是新的header</template>
            <template v-slot:main>哈哈哈哈</template>
            <template v-slot:default>我是默認的</template>
            <template v-slot:footer="title">{{ title.title.age }}</template>        
</slot-name>



<!-- v-slot的簡寫形式-->
<!-- 通過#號加上slot.vue中的對應插槽中的name屬性的值-->
<slot-name>
            <template #header>我是新的header</template>
            <template #footer="title">{{ title.title.age }}</template>
</slot-name>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM