技術文章
技術問答
iT 徵才
聊天室
2026 鐵人賽
登入/註冊
文章
問答
Tag
邦友
鐵人賽
搜尋
0
Vue文件:slots的使用時機, 運用
vue
vue3
relife12345
2025-11-18 17:37:50
‧
655 瀏覽
分享至
一、使用時機:slots通常使用在以下情境:
子元件寫好固定不變的html架構,父元件決定要動態改變的html。
子元件封裝共通程式碼邏輯(composables),子元件輸出的變數ref,曝露給父元件來呈現。套件很容易看到這種方式。
簡言之:
子元件不變,改父元件來達成動態顯示的差異
二、父元件說明:
複雜的情況時,多用子層<MyChild>包住<template>包住顯示內容{{ text num }},3層級來呈現。slot內容寫在<template>上面。
#head=”{ text, num}”可改寫
① v-slot:head=”{ text, num}”
② v-slot:head=”obj” 取值時,要 {{ obj.text obj.num }}
三、父層子層對照表:
父層工具
父層工具使用地方
子層工具
子層工具使用地方
v-slot or #
html attr
<slot>
html tag
name
html attr
$slots
程式碼表達式,寫在<slot>外層的html tag的v-if裡,決定顯不顯示
留言
追蹤
檢舉
熱門推薦
{{ item.subject }}
{{ item.channelVendor }}
|
{{ item.webinarstarted }}
|
{{ formatDate(item.duration) }}
直播中
立即報名
尚未有邦友留言
立即登入留言
iThome鐵人賽
參賽組數
902
組
團體組數
37
組
累計文章數
19837
篇
完賽人數
528
人
看影片追技術
看更多
{{ item.subject }}
{{ item.channelVendor }}
|
{{ formatDate(item.duration) }}
直播中
熱門tag
15th鐵人賽
16th鐵人賽
13th鐵人賽
14th鐵人賽
17th鐵人賽
12th鐵人賽
11th鐵人賽
鐵人賽
2019鐵人賽
javascript
2018鐵人賽
python
2017鐵人賽
windows
php
c#
linux
windows server
css
react
熱門問題
關於網路領域的相關知識精進與工作請益
執行BAT開啟teams的語法
Fortigate Remote Access
關於Aruba Wi-Fi (thin AP) controller設定
Seeed XIAO ESP32-S3 透過 UART (921600) 無法發送 AT 指令到 Grove Vision AI V2 (Himax WE2)
熱門回答
關於網路領域的相關知識精進與工作請益
執行BAT開啟teams的語法
Fortigate Remote Access
關於Aruba Wi-Fi (thin AP) controller設定
熱門文章
用 Claude AI 做了一個開源的 IT 故障排除工具,華文圈應該很稀缺
IT Diagnostic Agent 開發日誌 #1 為什麼我要做一個 IT Diagnostic Agent?
會議開完然後呢?我用 NotebookLM + MantisBT 打造「說到做到」的自動化追蹤流
IT Diagnostic Agent 開發日誌 #2 為什麼我原本不打算公開這個工具?
不只是 AI 幫你寫程式 — — OpenAI Codex 在做的是另一件事
IT邦幫忙
×
標記使用者
輸入對方的帳號或暱稱
Loading
找不到結果。
標記
{{ result.label }}
{{ result.account }}