W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗(yàn)值獎勵
通常,你需要通過 「slots」 向組件傳遞附加內(nèi)容。 假設(shè)我們創(chuàng)建的 alert
組件具有以下標(biāo)記:
<!-- /resources/views/components/alert.blade.php -->
<div class="alert alert-danger">
{{ $slot }}
</div>
我門可以通過向組件注入內(nèi)容的方式,將內(nèi)容傳遞到 slot
:
<x-alert>
<strong>Whoops!</strong> Something went wrong!
</x-alert>
有時候一個組件可能需要在它內(nèi)部的不同位置放置多個不同的插槽。我們來修改一下 alert 組件,使其允許注入 「title」:
<!-- /resources/views/components/alert.blade.php -->
<span class="alert-title">{{ $title }}</span>
<div class="alert alert-danger">
{{ $slot }}
</div>
您可以使用 x-slot
標(biāo)簽來定義命名插槽的內(nèi)容。任何沒有在 x-slot
標(biāo)簽中的內(nèi)容都將傳遞給 $slot
變量中的組件:
<x-alert>
<x-slot name="title">
Server Error
</x-slot>
<strong>Whoops!</strong> Something went wrong!
</x-alert>
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報電話:173-0602-2364|舉報郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: