[{"data":1,"prerenderedAt":3967},["ShallowReactive",2],{"all-posts":3,"post:\u002Fithome-2024-day-16":1210},[4,23,35,46,57,68,80,91,102,114,126,138,149,160,171,182,193,204,215,226,237,248,258,268,278,288,298,308,319,330,341,354,368,380,390,400,411,421,431,441,451,461,471,481,491,501,511,521,531,541,551,561,571,581,591,601,611,621,631,641,651,661,675,691,704,719,731,742,752,762,772,782,792,802,812,822,832,842,852,862,871,881,891,901,911,921,931,941,951,961,971,980,990,1000,1010,1020,1036,1050,1062,1073,1083,1095,1107,1121,1134,1145,1156,1167,1180,1191,1201],{"path":5,"title":6,"description":7,"date":8,"updated":9,"tags":10,"categories":14,"draft":15,"wordCount":16,"readingTime":17,"canonical":18,"series":19},"\u002Fithome-2026-day-30","Day 30：Angular Router Providers 與生命週期管理，路由離開後 Service 會銷毀嗎？","平常在 Angular 中，我們可以透過 providers 決定 Service 的注入範圍。例如註冊在 Root，讓整個 Application 共用同一個實例；或註冊在 Component，讓 Service 隨著…","2026-10-14T14:46:39+08:00",null,[11,12,13],"iThome 鐵人賽","2026 鐵人賽","Angular",[11,13],false,7227,7,"https:\u002F\u002Fithelp.ithome.com.tw\u002Farticles\u002F10424222",{"name":20,"url":21,"day":22},"2026 iThome 鐵人賽：Angular 22 Signal 進化論","https:\u002F\u002Fithelp.ithome.com.tw\u002Fusers\u002F20116554\u002Fironman\u002F9939",30,{"path":24,"title":25,"description":26,"date":27,"updated":9,"tags":28,"categories":29,"draft":15,"wordCount":30,"readingTime":31,"canonical":32,"series":33},"\u002Fithome-2026-day-29","Day 29：Angular 也有 VueUse？使用 Signality 整合常見 Browser API","在 Vue 生態系中，VueUse 提供許多 Composables，讓我們可以快速使用瀏覽器功能，例如監聽網路狀態、保存使用者設定，或偵測元素是否進入可視範圍。","2026-10-13T23:14:18+08:00",[11,12,13],[11,13],6387,6,"https:\u002F\u002Fithelp.ithome.com.tw\u002Farticles\u002F10424070",{"name":20,"url":21,"day":34},29,{"path":36,"title":37,"description":38,"date":39,"updated":9,"tags":40,"categories":41,"draft":15,"wordCount":42,"readingTime":31,"canonical":43,"series":44},"\u002Fithome-2026-day-28","Day 28：Angular 動態建立 Component，NgComponentOutlet 與 ViewContainerRef","平常在 Angular 中使用 Component，通常會直接在 Template 裡面宣告：","2026-10-12T17:27:41+08:00",[11,12,13],[11,13],6565,"https:\u002F\u002Fithelp.ithome.com.tw\u002Farticles\u002F10423641",{"name":20,"url":21,"day":45},28,{"path":47,"title":48,"description":49,"date":50,"updated":9,"tags":51,"categories":52,"draft":15,"wordCount":53,"readingTime":17,"canonical":54,"series":55},"\u002Fithome-2026-day-27","Day 27：NgRx Store vs SignalStore，從 Action、Reducer 到直接更新 State","前幾天我們使用 NgRx SignalStore 實作購物車，透過 withState() 管理商品資料、withComputed() 計算總金額，再利用 withMethods() 與 patchState() 更新 …","2026-10-11T20:06:41+08:00",[11,12,13],[11,13],7308,"https:\u002F\u002Fithelp.ithome.com.tw\u002Farticles\u002F10423362",{"name":20,"url":21,"day":56},27,{"path":58,"title":59,"description":60,"date":61,"updated":9,"tags":62,"categories":63,"draft":15,"wordCount":64,"readingTime":17,"canonical":65,"series":66},"\u002Fithome-2026-day-26","Day 26：SignalStore 與 Strategy Pattern，透過 DI 動態切換業務邏輯","昨天我們使用 Angular 原生 Signal 與 NgRx SignalStore 實作購物車，透過 State 管理商品資料，再利用 Computed 計算商品數量與總金額。","2026-10-10T22:01:59+08:00",[11,12,13],[11,13],7347,"https:\u002F\u002Fithelp.ithome.com.tw\u002Farticles\u002F10423116",{"name":20,"url":21,"day":67},26,{"path":69,"title":70,"description":71,"date":72,"updated":9,"tags":73,"categories":74,"draft":15,"wordCount":75,"readingTime":76,"canonical":77,"series":78},"\u002Fithome-2026-day-25","Day 25：Angular SignalStore，原生 Signal 不夠用嗎？","在 Angular 開發中，如果資料只會被單一 Component 使用，通常可以直接透過 signal() 管理。但當多個 Component 需要共用同一份資料時，就得考慮狀態應該放在哪裡。","2026-10-09T21:28:45+08:00",[11,12,13],[11,13],9117,9,"https:\u002F\u002Fithelp.ithome.com.tw\u002Farticles\u002F10422784",{"name":20,"url":21,"day":79},25,{"path":81,"title":82,"description":83,"date":84,"updated":9,"tags":85,"categories":86,"draft":15,"wordCount":87,"readingTime":31,"canonical":88,"series":89},"\u002Fithome-2026-day-24","Day 24：SPA Router 為什麼不再只靠 History API？","平常使用 Angular Router 時，可以透過 routerLink 或 router.navigate() 切換不同頁面。","2026-10-08T14:30:47+08:00",[11,12,13],[11,13],6330,"https:\u002F\u002Fithelp.ithome.com.tw\u002Farticles\u002F10422348",{"name":20,"url":21,"day":90},24,{"path":92,"title":93,"description":94,"date":95,"updated":9,"tags":96,"categories":97,"draft":15,"wordCount":98,"readingTime":17,"canonical":99,"series":100},"\u002Fithome-2026-day-23","Day 23：RouteReuseStrategy，切換路由一定要銷毀 Component 嗎？","在後台系統中，很常會看到頁籤式介面，例如：","2026-10-07T15:58:32+08:00",[11,12,13],[11,13],7361,"https:\u002F\u002Fithelp.ithome.com.tw\u002Farticles\u002F10422016",{"name":20,"url":21,"day":101},23,{"path":103,"title":104,"description":105,"date":106,"updated":9,"tags":107,"categories":108,"draft":15,"wordCount":109,"readingTime":110,"canonical":111,"series":112},"\u002Fithome-2026-day-22","Day 22：Angular Render Lifecycle，從 afterNextRender 到 DestroyRef","過去在 Angular 中，只要遇到初始化、View 建立或資源清理，通常會先想到 Lifecycle Hooks：","2026-10-06T23:36:23+08:00",[11,12,13],[11,13],8111,8,"https:\u002F\u002Fithelp.ithome.com.tw\u002Farticles\u002F10421810",{"name":20,"url":21,"day":113},22,{"path":115,"title":116,"description":117,"date":118,"updated":9,"tags":119,"categories":120,"draft":15,"wordCount":121,"readingTime":122,"canonical":123,"series":124},"\u002Fithome-2026-day-21","Day 21：Angular Template 還適合呼叫 Method 嗎？從 Pipe、RxJS 到 computed","過去在寫 Angular 時，因為 Template 可以直接呼叫 Method，很容易在專案裡看到大量這樣的寫法。","2026-10-05T23:30:32+08:00",[11,12,13],[11,13],5431,5,"https:\u002F\u002Fithelp.ithome.com.tw\u002Farticles\u002F10421425",{"name":20,"url":21,"day":125},21,{"path":127,"title":128,"description":129,"date":130,"updated":9,"tags":131,"categories":132,"draft":15,"wordCount":133,"readingTime":134,"canonical":135,"series":136},"\u002Fithome-2026-day-20","Day 20：Signal Forms 非同步驗證，validateHttp 與 validateAsync","前兩篇介紹了 Signal Forms 的基本驗證，以及需要參考其他欄位的 Cross-field Validation。","2026-10-04T20:56:17+08:00",[11,12,13],[11,13],4278,4,"https:\u002F\u002Fithelp.ithome.com.tw\u002Farticles\u002F10420910",{"name":20,"url":21,"day":137},20,{"path":139,"title":140,"description":141,"date":142,"updated":9,"tags":143,"categories":144,"draft":15,"wordCount":145,"readingTime":134,"canonical":146,"series":147},"\u002Fithome-2026-day-19","Day 19：Signal Forms Cross-field Validation 與欄位更新時機","上一篇介紹 Signal Forms 時，已經看到可以透過 Schema 定義欄位驗證，例如 required()、email()、minLength()。","2026-10-03T23:18:26+08:00",[11,12,13],[11,13],3783,"https:\u002F\u002Fithelp.ithome.com.tw\u002Farticles\u002F10420631",{"name":20,"url":21,"day":148},19,{"path":150,"title":151,"description":152,"date":153,"updated":9,"tags":154,"categories":155,"draft":15,"wordCount":156,"readingTime":31,"canonical":157,"series":158},"\u002Fithome-2026-day-18","Day 18：Angular Signal Forms 穩定了，跟我們用了這麼久的 Reactive Forms 到底差在哪？","在 Angular 中處理表單，很多專案使用的都是 Reactive Forms。","2026-10-02T23:28:36+08:00",[11,12,13],[11,13],5886,"https:\u002F\u002Fithelp.ithome.com.tw\u002Farticles\u002F10420249",{"name":20,"url":21,"day":159},18,{"path":161,"title":162,"description":163,"date":164,"updated":9,"tags":165,"categories":166,"draft":15,"wordCount":167,"readingTime":31,"canonical":168,"series":169},"\u002Fithome-2026-day-17","Day 17：effect() 不是拿來同步 Signal 的，Angular 的 Side Effect 該怎麼寫？","effect() 是 Angular signal 裡很容易被誤用的一個 API。因為寫法直覺，只要讀取 signal，就能在值改變時執行一些事情，所以很常被拿來同步狀態、打 API，甚至再去修改其他 signal。","2026-10-01T21:22:13+08:00",[11,12,13],[11,13],6473,"https:\u002F\u002Fithelp.ithome.com.tw\u002Farticles\u002F10419779",{"name":20,"url":21,"day":170},17,{"path":172,"title":173,"description":174,"date":175,"updated":9,"tags":176,"categories":177,"draft":15,"wordCount":178,"readingTime":31,"canonical":179,"series":180},"\u002Fithome-2026-day-16","Day 16：即將登場的 Route Resources，Angular Router 為什麼需要新的資料載入方式？","過去在 Angular Router 中，如果希望進入 Component 前先完成資料載入，可以透過 Resolver，讓資料取得流程在 Component 初始化之前執行。","2026-09-30T23:12:05+08:00",[11,12,13],[11,13],6534,"https:\u002F\u002Fithelp.ithome.com.tw\u002Farticles\u002F10419409",{"name":20,"url":21,"day":181},16,{"path":183,"title":184,"description":185,"date":186,"updated":9,"tags":187,"categories":188,"draft":15,"wordCount":189,"readingTime":17,"canonical":190,"series":191},"\u002Fithome-2026-day-15","Day 15：搞懂 Injection Context，從 inject()、runInInjectionContext() 到 injectAsync()","前面提到 Injection Context 時，可能會讓人聯想到先前介紹過的 Reactive Context。我一開始也有點搞混，因此花了一些時間重新理解 Angular 裡這些不同的執行環境。","2026-09-29T13:44:28+08:00",[11,12,13],[11,13],6986,"https:\u002F\u002Fithelp.ithome.com.tw\u002Farticles\u002F10418752",{"name":20,"url":21,"day":192},15,{"path":194,"title":195,"description":196,"date":197,"updated":9,"tags":198,"categories":199,"draft":15,"wordCount":200,"readingTime":17,"canonical":201,"series":202},"\u002Fithome-2026-day-14","Day 14：Lazy Loading 不只一種，從 Router Preloading、@defer 到 injectAsync()","當 Client Side Rendering 的應用越來越大時，我們通常會開始思考，能不能把原本一次載入的內容拆得更小，等到真正需要時再下載，避免初始載入過多 JavaScript，拉長畫面呈現的時間。","2026-09-28T22:44:46+08:00",[11,12,13],[11,13],7674,"https:\u002F\u002Fithelp.ithome.com.tw\u002Farticles\u002F10418485",{"name":20,"url":21,"day":203},14,{"path":205,"title":206,"description":207,"date":208,"updated":9,"tags":209,"categories":210,"draft":15,"wordCount":211,"readingTime":110,"canonical":212,"series":213},"\u002Fithome-2026-day-13","Day 13：從 Router Event 到 Signal","路由狀態管理在前端開發中比較少被單獨拿出來討論，但在 Angular 裡，一次路由導航其實會經過不少階段，也會在過程中發出不同的 Router Event，例如 NavigationStart、NavigationEnd…","2026-09-27T20:37:55+08:00",[11,12,13],[11,13],7777,"https:\u002F\u002Fithelp.ithome.com.tw\u002Farticles\u002F10417948",{"name":20,"url":21,"day":214},13,{"path":216,"title":217,"description":218,"date":219,"updated":9,"tags":220,"categories":221,"draft":15,"wordCount":222,"readingTime":122,"canonical":223,"series":224},"\u002Fithome-2026-day-12","Day 12：從 httpResource 到 TanStack Query，認識 Server State","前面我們花了不少時間討論，為什麼「請求本身的狀態」和「元件的顯示狀態」應該分開處理。","2026-09-26T23:35:12+08:00",[11,12,13],[11,13],5119,"https:\u002F\u002Fithelp.ithome.com.tw\u002Farticles\u002F10417614",{"name":20,"url":21,"day":225},12,{"path":227,"title":228,"description":229,"date":230,"updated":9,"tags":231,"categories":232,"draft":15,"wordCount":233,"readingTime":122,"canonical":234,"series":235},"\u002Fithome-2026-day-11","Day 11：用 rxResource 串起 Observable 與 Resource","前面介紹了不少 Resource 到 httpResource() 的應用。不過在 Angular 開發中，Observable 與 RxJS 仍然是很常見的非同步資料處理方式，像是 switchMap、map、debo…","2026-09-25T22:42:04+08:00",[11,12,13],[11,13],4908,"https:\u002F\u002Fithelp.ithome.com.tw\u002Farticles\u002F10417143",{"name":20,"url":21,"day":236},11,{"path":238,"title":239,"description":240,"date":241,"updated":9,"tags":242,"categories":243,"draft":15,"wordCount":244,"readingTime":31,"canonical":245,"series":246},"\u002Fithome-2026-day-10","Day 10：linkedSignal 讓相依狀態也能被修改","昨天我們透過 httpResource() 搭配 chain() 處理兩個非同步資料之間的依賴。下游 Request 需要使用上游資料時，會等上游完成後再繼續；當 Request 的來源改變，Resource 的狀態也會…","2026-09-24T23:49:49+08:00",[11,12,13],[11,13],5623,"https:\u002F\u002Fithelp.ithome.com.tw\u002Farticles\u002F10416746",{"name":20,"url":21,"day":247},10,{"path":249,"title":250,"description":251,"date":252,"updated":9,"tags":253,"categories":254,"draft":15,"wordCount":255,"readingTime":134,"canonical":256,"series":257},"\u002Fithome-2026-day-09","Day 9：httpResource 實務篇，統一回覆格式與 chain 相依請求","昨天我們透過 Orval 串起 API Contract，了解如何根據 OpenAPI 規格產生前端需要的型別與 API 呼叫方式。","2026-09-23T23:42:40+08:00",[11,12,13],[11,13],4358,"https:\u002F\u002Fithelp.ithome.com.tw\u002Farticles\u002F10416227",{"name":20,"url":21,"day":76},{"path":259,"title":260,"description":261,"date":262,"updated":9,"tags":263,"categories":264,"draft":15,"wordCount":265,"readingTime":122,"canonical":266,"series":267},"\u002Fithome-2026-day-08","Day 8：用 Orval 串起 Angular API Contract，同時產生 HttpClient、httpResource 與 Zod","前後端在對接 API 時，常見的問題之一，就是雙方對資料格式的定義逐漸不一致。","2026-09-22T23:48:12+08:00",[11,12,13],[11,13],4451,"https:\u002F\u002Fithelp.ithome.com.tw\u002Farticles\u002F10415694",{"name":20,"url":21,"day":110},{"path":269,"title":270,"description":271,"date":272,"updated":9,"tags":273,"categories":274,"draft":15,"wordCount":275,"readingTime":17,"canonical":276,"series":277},"\u002Fithome-2026-day-07","Day 7：從 Resource 到 httpResource，用 Signal 管理 HTTP 資料請求","昨天我們提到，Resource API 本身是一套通用的非同步資料模型，比較適合用在「讀取資料」這類情境，而不是新增、修改或刪除資料這種 Mutation 操作。","2026-09-21T22:13:18+08:00",[11,12,13],[11,13],6735,"https:\u002F\u002Fithelp.ithome.com.tw\u002Farticles\u002F10415038",{"name":20,"url":21,"day":17},{"path":279,"title":280,"description":281,"date":282,"updated":9,"tags":283,"categories":284,"draft":15,"wordCount":285,"readingTime":122,"canonical":286,"series":287},"\u002Fithome-2026-day-06","Day 6：Resource API，把非同步資料帶進 Signal","今天來看 Angular Signal 裡一個很重要的非同步資料 API：Resource API。","2026-09-20T19:25:37+08:00",[11,12,13],[11,13],5054,"https:\u002F\u002Fithelp.ithome.com.tw\u002Farticles\u002F10414377",{"name":20,"url":21,"day":31},{"path":289,"title":290,"description":291,"date":292,"updated":9,"tags":293,"categories":294,"draft":15,"wordCount":295,"readingTime":134,"canonical":296,"series":297},"\u002Fithome-2026-day-05","Day 5：從 Reactive Graph 到 View Tree，看 Angular 如何找到真正需要更新的畫面","前面我們已經知道，當 Signal 的值發生變化後，Angular 會透過 Reactive Graph 找到受到影響的 Consumer。","2026-09-19T20:19:47+08:00",[11,12,13],[11,13],4364,"https:\u002F\u002Fithelp.ithome.com.tw\u002Farticles\u002F10413852",{"name":20,"url":21,"day":122},{"path":299,"title":300,"description":301,"date":302,"updated":9,"tags":303,"categories":304,"draft":15,"wordCount":305,"readingTime":122,"canonical":306,"series":307},"\u002Fithome-2026-day-04","Day 4：Angular 怎麼知道誰正在讀 Signal？從 Reactive Context 理解依賴追蹤","前面我們看過，當 Template 讀取 Signal 時，Angular 會記住「誰依賴了誰」；當 Signal 發生變化後，也會透過 Reactive Graph 通知相關的 Consumer。","2026-09-18T21:58:16+08:00",[11,12,13],[11,13],4894,"https:\u002F\u002Fithelp.ithome.com.tw\u002Farticles\u002F10413313",{"name":20,"url":21,"day":134},{"path":309,"title":310,"description":311,"date":312,"updated":9,"tags":313,"categories":314,"draft":15,"wordCount":315,"readingTime":122,"canonical":316,"series":317},"\u002Fithome-2026-day-03","Day 3：從 set()、update() 看懂 Angular Signal 的基本使用與更新機制","昨天我們先試著理解，在 Template 中使用 Signal() 時，Angular 是如何建立依賴關係，並在 Signal 發生變化後，知道哪些 View 可能受到影響。","2026-09-17T23:08:58+08:00",[11,12,13],[11,13],5451,"https:\u002F\u002Fithelp.ithome.com.tw\u002Farticles\u002F10412826",{"name":20,"url":21,"day":318},3,{"path":320,"title":321,"description":322,"date":323,"updated":9,"tags":324,"categories":325,"draft":15,"wordCount":326,"readingTime":134,"canonical":327,"series":328},"\u002Fithome-2026-day-02","Day 2：Angular Signal 是什麼？從 Change Detection 理解它的運作原理","傳統 Angular 在監測資料變化時，通常會搭配 zone.js。像是 DOM 事件、Promise、Timer、HTTP 請求這些非同步操作發生時，zone.js 會幫忙攔截。","2026-09-16T20:19:12+08:00",[11,12,13],[11,13],4276,"https:\u002F\u002Fithelp.ithome.com.tw\u002Farticles\u002F10411944",{"name":20,"url":21,"day":329},2,{"path":331,"title":332,"description":333,"date":334,"updated":9,"tags":335,"categories":336,"draft":15,"wordCount":337,"readingTime":329,"canonical":338,"series":339},"\u002Fithome-2026-day-01","Day 1：為什麼想聊 Angular Signal？","相信講到前端框架，大家第一時間想到的通常會是 Vue、React，甚至也有人會推薦 Svelte 這類近年討論度很高的框架。但一講到 Angular，很多人的第一印象可能就像看到一座大城堡一樣：東西很多、規則很多，一時之…","2026-09-15T23:56:26+08:00",[11,12,13],[11,13],1478,"https:\u002F\u002Fithelp.ithome.com.tw\u002Farticles\u002F10411425",{"name":20,"url":21,"day":340},1,{"path":342,"title":343,"description":344,"date":345,"updated":9,"tags":346,"categories":351,"draft":15,"wordCount":353,"readingTime":134,"canonical":9,"series":9},"\u002FTS-Excess-Property-Checks","TypeScript 踩坑筆記：物件字面量的多餘屬性檢查機制","深入探討 TypeScript 的多餘屬性檢查（Excess Property Checks）機制，解析物件字面量與變數賦值的型別檢查差異，並提供實務開發中避免型別陷阱的最佳實踐方法。","2026-01-31T16:29:23+08:00",[347,348,349,350],"Excess Property Checks","Structural Typing","Type Safety","NestJS",[352],"TypeScript",3551,{"path":355,"title":356,"description":357,"date":358,"updated":9,"tags":359,"categories":361,"draft":15,"wordCount":363,"readingTime":329,"canonical":364,"series":365},"\u002Fithome-2025-day-30","Day 30：開發之旅完結 - 感謝與展望","終於來到鐵人賽的最後一天！這是我第二次參加鐵人賽，今年的主題是 LINE Bot 開發。這個主題源自於我參加的十二週讀書會分享，當時我發現大家對 LINE Bot 很感興趣，而我自己也一直很喜歡這個主題，於是早在六月就定…","2025-10-13T20:11:12+08:00",[11,360],"2025 鐵人賽",[11,362],"Line Bot",1751,"https:\u002F\u002Fithelp.ithome.com.tw\u002Farticles\u002F10396850",{"name":366,"url":367,"day":22},"2025 iThome 鐵人賽：Line Bot × NestJS：30 天開發日記","https:\u002F\u002Fithelp.ithome.com.tw\u002Fusers\u002F20116554\u002Fironman\u002F8779",{"path":369,"title":370,"description":371,"date":372,"updated":9,"tags":373,"categories":376,"draft":15,"wordCount":377,"readingTime":31,"canonical":378,"series":379},"\u002Fithome-2025-day-29","Day 29：LIFF 會員註冊 - 信箱驗證與 Swagger 文件整合","延續 Day 28 會員註冊的流程，在實際的會員註冊場景中，電子信箱驗證是確保用戶身份真實性的重要環節。本篇將基於昨天的註冊流程，新增兩個核心 API：發送驗證信與驗證驗證碼，讓會員註冊功能更加完整且安全。","2025-10-12T23:15:00+08:00",[11,360,362,374,350,375],"LIFF","Swagger",[11,362],6089,"https:\u002F\u002Fithelp.ithome.com.tw\u002Farticles\u002F10396512",{"name":366,"url":367,"day":34},{"path":381,"title":382,"description":383,"date":384,"updated":9,"tags":385,"categories":386,"draft":15,"wordCount":387,"readingTime":122,"canonical":388,"series":389},"\u002Fithome-2025-day-28","Day 28：LIFF 會員註冊 - ID Token 驗證與資料庫整合","今天的開發重點是建立會員卡系統，將 LIFF 前端與 NestJS 後端完整串接。","2025-10-11T22:57:29+08:00",[11,360,362,374,350],[11,362],5254,"https:\u002F\u002Fithelp.ithome.com.tw\u002Farticles\u002F10396146",{"name":366,"url":367,"day":45},{"path":391,"title":392,"description":393,"date":394,"updated":9,"tags":395,"categories":396,"draft":15,"wordCount":397,"readingTime":318,"canonical":398,"series":399},"\u002Fithome-2025-day-27","Day 27：群組事件與檔案訊息接收","今天主要補充 LINE Bot 在群組中的專屬特性，包括群組限定的 Webhook 事件，以及前面提到但尚未說明的第 7 種訊息類型 file 檔案訊息。","2025-10-10T21:01:52+08:00",[11,360,362,350],[11,362],2888,"https:\u002F\u002Fithelp.ithome.com.tw\u002Farticles\u002F10395785",{"name":366,"url":367,"day":56},{"path":401,"title":402,"description":403,"date":404,"updated":9,"tags":405,"categories":407,"draft":15,"wordCount":408,"readingTime":122,"canonical":409,"series":410},"\u002Fithome-2025-day-26","Day 26：LINE Pay 線上付款","LINE Pay 提供兩種付款方式：線上付款與實體付款。實體付款主要採用店家出示條碼的模式，顧客掃描後即可輸入金額完成付款。這兩種付款方式都支援在沙盒(Sandbox)環境中進行測試。本文將著重說明線上付款的整合流程。","2025-10-09T23:39:32+08:00",[11,360,406],"Line Pay",[11,362],4876,"https:\u002F\u002Fithelp.ithome.com.tw\u002Farticles\u002F10395481",{"name":366,"url":367,"day":67},{"path":412,"title":413,"description":414,"date":415,"updated":9,"tags":416,"categories":417,"draft":15,"wordCount":418,"readingTime":318,"canonical":419,"series":420},"\u002Fithome-2025-day-25","Day 25：優惠券設定與 Coupon Message 實作","LINE Official Account 的「優惠券」是提升顧客互動與忠誠度的重要功能。透過獎勵機制，不僅能吸引新客，更能有效促進回購。","2025-10-08T23:49:32+08:00",[11,360,362,350],[11,362],3207,"https:\u002F\u002Fithelp.ithome.com.tw\u002Farticles\u002F10395076",{"name":366,"url":367,"day":79},{"path":422,"title":423,"description":424,"date":425,"updated":9,"tags":426,"categories":427,"draft":15,"wordCount":428,"readingTime":134,"canonical":429,"series":430},"\u002Fithome-2025-day-24","Day 24：LIFF 刮刮樂實戰體驗","在了解 LIFF 的基礎設計流程後，本文將透過「刮刮樂」案例示範 LIFF API 的實際應用。從啟動時檢查權限與執行環境、確認用戶分享功能權限，到刮刮樂結束後發送訊息並關閉 LIFF，完整呈現 LIFF 在互動應用中的…","2025-10-07T22:36:58+08:00",[11,360,362,374],[11,362],4200,"https:\u002F\u002Fithelp.ithome.com.tw\u002Farticles\u002F10394618",{"name":366,"url":367,"day":90},{"path":432,"title":433,"description":434,"date":435,"updated":9,"tags":436,"categories":437,"draft":15,"wordCount":438,"readingTime":134,"canonical":439,"series":440},"\u002Fithome-2025-day-23","Day 23：LIFF 網頁應用開發入門","在鐵人賽前半段，我們深入探討了 LINE Bot 的兩大核心功能：Richmenu(選單設置)與各種 Reply Message(回覆訊息)的訊息類型。然而在實務應用中，若要提供更豐富的互動體驗，Line 往往需要搭配 …","2025-10-06T23:06:57+08:00",[11,360,362,374],[11,362],4400,"https:\u002F\u002Fithelp.ithome.com.tw\u002Farticles\u002F10394035",{"name":366,"url":367,"day":101},{"path":442,"title":443,"description":444,"date":445,"updated":9,"tags":446,"categories":447,"draft":15,"wordCount":448,"readingTime":329,"canonical":449,"series":450},"\u002Fithome-2025-day-22","Day 22：Render 雲端平台部署 Nest 後端伺服器","今天的目標是將系統正式上線。經過這段時間的開發，我們已完成 Line Message API 的核心功能與日誌處理機制。","2025-10-05T22:52:11+08:00",[11,360,362,350],[11,362],1895,"https:\u002F\u002Fithelp.ithome.com.tw\u002Farticles\u002F10393809",{"name":366,"url":367,"day":113},{"path":452,"title":453,"description":454,"date":455,"updated":9,"tags":456,"categories":457,"draft":15,"wordCount":458,"readingTime":318,"canonical":459,"series":460},"\u002Fithome-2025-day-21","Day 21：Nest Pino 整合 Grafana Loki 日誌","Loki 環境變數可參考 Day 20 文章的 Grafana Data Source settings 設定","2025-10-04T17:24:26+08:00",[11,360,362,350],[11,362],2740,"https:\u002F\u002Fithelp.ithome.com.tw\u002Farticles\u002F10393305",{"name":366,"url":367,"day":125},{"path":462,"title":463,"description":464,"date":465,"updated":9,"tags":466,"categories":467,"draft":15,"wordCount":468,"readingTime":318,"canonical":469,"series":470},"\u002Fithome-2025-day-20","Day 20：Grafana Loki 日誌服務 - 從申請到 API 串接測試","目前已經理解了 LINE Messaging API 的核心功能，包括如何接收訊息、串接第三方服務，以及發送多種類型的訊息。接下來，我們將把原本架設在 ngrok 的後端伺服器，透過 GitHub 自動化部署到 Rend…","2025-10-03T23:16:16+08:00",[11,360,362,350],[11,362],2461,"https:\u002F\u002Fithelp.ithome.com.tw\u002Farticles\u002F10392910",{"name":366,"url":367,"day":137},{"path":472,"title":473,"description":474,"date":475,"updated":9,"tags":476,"categories":477,"draft":15,"wordCount":478,"readingTime":318,"canonical":479,"series":480},"\u002Fithome-2025-day-19","Day 19：Flex Message Carousel 食譜分享","Flex Message 可以分成 bubble(單張卡片) 跟 carousel(多張卡片輪播) 兩種方式，昨天示範了 bubble 格式的電子個人名片後，今天主要展示 carousel 的應用，兩者的基本結構大致相同…","2025-10-02T16:06:17+08:00",[11,360,362,350],[11,362],2267,"https:\u002F\u002Fithelp.ithome.com.tw\u002Farticles\u002F10392256",{"name":366,"url":367,"day":148},{"path":482,"title":483,"description":484,"date":485,"updated":9,"tags":486,"categories":487,"draft":15,"wordCount":488,"readingTime":122,"canonical":489,"series":490},"\u002Fithome-2025-day-18","Day 18：Flex Message 設計個人名片","從基礎的文字互動開始，我們逐步探索了六大核心訊息類型的發送機制、Template Message 的結構化設計，以及 ImageMap Message 的互動式體驗。今天，我們將進入 LINE Bot 最具彈性的訊息格式…","2025-10-01T17:57:47+08:00",[11,360,362,350],[11,362],4468,"https:\u002F\u002Fithelp.ithome.com.tw\u002Farticles\u002F10391723",{"name":366,"url":367,"day":159},{"path":492,"title":493,"description":494,"date":495,"updated":9,"tags":496,"categories":497,"draft":15,"wordCount":498,"readingTime":122,"canonical":499,"series":500},"\u002Fithome-2025-day-17","Day 17：ImageMap Message  從互動海報到影片嵌入","在 Day 16 文章中，我們使用 Cloudflare Workers 實作了圖片代理功能。到目前為止，我們已經完成以下準備工作:","2025-09-30T11:58:32+08:00",[11,360,362,350],[11,362],4807,"https:\u002F\u002Fithelp.ithome.com.tw\u002Farticles\u002F10391164",{"name":366,"url":367,"day":170},{"path":502,"title":503,"description":504,"date":505,"updated":9,"tags":506,"categories":507,"draft":15,"wordCount":508,"readingTime":134,"canonical":509,"series":510},"\u002Fithome-2025-day-16","Day 16：Cloudflare Workers 圖片代理實作","在 Day 15 文章中，我們處理了 ImageMap Message 的背景圖，接著我們遇到了圖片不能出現副檔名及動態路徑支援不同解析度的問題。今天主要會透過 Cloudflare Workers 來解決這兩個問題，讓…","2025-09-29T16:15:41+08:00",[11,360,362,350],[11,362],3412,"https:\u002F\u002Fithelp.ithome.com.tw\u002Farticles\u002F10390567",{"name":366,"url":367,"day":181},{"path":512,"title":513,"description":514,"date":515,"updated":9,"tags":516,"categories":517,"draft":15,"wordCount":518,"readingTime":134,"canonical":519,"series":520},"\u002Fithome-2025-day-15","Day 15：共通屬性處理優化及 Imagemap  圖片製作","針對 Day 14 的程式碼架構進行優化。由於 Sender 和 Quick Reply 功能在所有回覆訊息類型中都能使用，我們應該將這些共用屬性抽取為獨立函數進行統一處理。","2025-09-28T21:03:38+08:00",[11,360,362,350],[11,362],4033,"https:\u002F\u002Fithelp.ithome.com.tw\u002Farticles\u002F10389697",{"name":366,"url":367,"day":192},{"path":522,"title":523,"description":524,"date":525,"updated":9,"tags":526,"categories":527,"draft":15,"wordCount":528,"readingTime":31,"canonical":529,"series":530},"\u002Fithome-2025-day-14","Day 14：LINE Bot Template Message 訊息回覆","經過前幾天的學習，我們已經成功掌握了 LINE Bot 六大基礎訊息類型的發送技巧，為訊息互動奠定了穩固的基礎。今天，我們將踏入更具挑戰性的進階應用領域！","2025-09-27T15:54:06+08:00",[11,360,362,350],[11,362],6372,"https:\u002F\u002Fithelp.ithome.com.tw\u002Farticles\u002F10388976",{"name":366,"url":367,"day":203},{"path":532,"title":533,"description":534,"date":535,"updated":9,"tags":536,"categories":537,"draft":15,"wordCount":538,"readingTime":122,"canonical":539,"series":540},"\u002Fithome-2025-day-13","Day 13：LINE Bot 客製化 Sender 與 Quick Reply 功能實作","LINE Bot 所有回覆訊息類型都具備「共用屬性」功能，這些屬性帶來兩項重要的互動體驗提升：","2025-09-26T11:41:34+08:00",[11,360,362,350],[11,362],4426,"https:\u002F\u002Fithelp.ithome.com.tw\u002Farticles\u002F10388037",{"name":366,"url":367,"day":214},{"path":542,"title":543,"description":544,"date":545,"updated":9,"tags":546,"categories":547,"draft":15,"wordCount":548,"readingTime":318,"canonical":549,"series":550},"\u002Fithome-2025-day-12","Day 12：LINE Bot Image、Video、Audio、Location 訊息回覆","Day 11 文章中，我們針對 LINE Bot 可以回覆的Text及Sticker基礎型別進行了封裝，不僅新增了 line-message.ts模組，還讓開發者可以用最少的參數產生 LINE Message 所需要的格…","2025-09-25T18:08:09+08:00",[11,360,362,350],[11,362],2977,"https:\u002F\u002Fithelp.ithome.com.tw\u002Farticles\u002F10387598",{"name":366,"url":367,"day":225},{"path":552,"title":553,"description":554,"date":555,"updated":9,"tags":556,"categories":557,"draft":15,"wordCount":558,"readingTime":31,"canonical":559,"series":560},"\u002Fithome-2025-day-11","Day 11：LINE Bot Text Emoji 與 Sticker 訊息回覆","目前我們的 LINE Bot 主要使用 Text 方式回覆訊息。今天將探討 Text 類型的 Emoji 應用，以及 Sticker 回覆方式，基於 Day 8 版本進行改寫。","2025-09-24T23:21:11+08:00",[11,360,350,362],[11,362],5659,"https:\u002F\u002Fithelp.ithome.com.tw\u002Farticles\u002F10386993",{"name":366,"url":367,"day":236},{"path":562,"title":563,"description":564,"date":565,"updated":9,"tags":566,"categories":567,"draft":15,"wordCount":568,"readingTime":318,"canonical":569,"series":570},"\u002Fithome-2025-day-10","Day 10：LINE Rich Menu Switch Action 提升使用者體驗","在 Day 9 文章中，我們結合 LINE 平台的功能，將天氣服務與圖片上傳服務整合，打造出第一張 LINE 圖文選單，透過 URI action 的方式觸發平台提供的互動效果。接著，我們使用客製化選單製作出 9 格的客…","2025-09-23T15:02:57+08:00",[11,360,362,350],[11,362],2906,"https:\u002F\u002Fithelp.ithome.com.tw\u002Farticles\u002F10386165",{"name":366,"url":367,"day":247},{"path":572,"title":573,"description":574,"date":575,"updated":9,"tags":576,"categories":577,"draft":15,"wordCount":578,"readingTime":318,"canonical":579,"series":580},"\u002Fithome-2025-day-09","Day  9：打造 LINE Rich Menu - 後台設計 vs API 客製化","在 Day8 文章中，我們透過整合雲端服務 Cloudinary，學習如何處理使用者上傳的圖片檔案，並將其儲存至雲端。然而，LINE Bot 除了讓使用者輸入文字回覆的方式之外，更常見的是透過圖文選單(Rich Menu…","2025-09-22T21:54:25+08:00",[11,360,362,350],[11,362],3285,"https:\u002F\u002Fithelp.ithome.com.tw\u002Farticles\u002F10385658",{"name":366,"url":367,"day":76},{"path":582,"title":583,"description":584,"date":585,"updated":9,"tags":586,"categories":587,"draft":15,"wordCount":588,"readingTime":17,"canonical":589,"series":590},"\u002Fithome-2025-day-08","Day 8：Cloudinary 雲端圖片儲存整合","在 Day 6 中，我們透過整合 OpenWeatherMap API 與座標位置訊息學習了如何結合第三方服務。今天將探索 Cloudinary 雲端服務，解決 LINE 圖片資源會過期的問題，學習如何透過 LINE M…","2025-09-21T23:13:19+08:00",[11,360,362,350],[11,362],7215,"https:\u002F\u002Fithelp.ithome.com.tw\u002Farticles\u002F10384968",{"name":366,"url":367,"day":110},{"path":592,"title":593,"description":594,"date":595,"updated":9,"tags":596,"categories":597,"draft":15,"wordCount":598,"readingTime":122,"canonical":599,"series":600},"\u002Fithome-2025-day-07","Day 7：Joi 環境變數統一驗證，重構 LINE Bot 天氣服務模組","在 Day 6 開發 LINE Bot 結合 OpenWeatherMap API 的過程中，我們採用私有方法將 API 請求處理與資料格式化整合在一起。今天將對 Day 6 的實作進行架構重構，主要目標是建立更完善的環…","2025-09-20T23:07:08+08:00",[11,360,362,350],[11,362],5157,"https:\u002F\u002Fithelp.ithome.com.tw\u002Farticles\u002F10384302",{"name":366,"url":367,"day":17},{"path":602,"title":603,"description":604,"date":605,"updated":9,"tags":606,"categories":607,"draft":15,"wordCount":608,"readingTime":134,"canonical":609,"series":610},"\u002Fithome-2025-day-06","Day 6：整合第三方 API 天氣查詢服務","Day 5 帶大家了解 LINE Bot 能接收使用者傳遞的「6+1」種訊息類型。之所以這樣強調，是因為 File 類型僅能在群組聊天中使用，這個限制我自己也經常忘記，所以習慣用「6+1」來提醒自己。","2025-09-19T21:07:47+08:00",[11,360,362,350],[11,362],3892,"https:\u002F\u002Fithelp.ithome.com.tw\u002Farticles\u002F10383636",{"name":366,"url":367,"day":31},{"path":612,"title":613,"description":614,"date":615,"updated":9,"tags":616,"categories":617,"draft":15,"wordCount":618,"readingTime":122,"canonical":619,"series":620},"\u002Fithome-2025-day-05","Day 5：整合 Pino Logger 提升 LINE Bot 專案的可維護性","看著專案逐漸成型，現在該開始重視日誌記錄的規劃了。在實際部署時，我們通常會區分 develop(開發環境)和 production(正式環境)兩種不同的執行環境，針對不同環境採用相應的日誌策略。","2025-09-18T23:30:00+08:00",[11,360,362,350],[11,362],4746,"https:\u002F\u002Fithelp.ithome.com.tw\u002Farticles\u002F10382298",{"name":366,"url":367,"day":122},{"path":622,"title":623,"description":624,"date":625,"updated":9,"tags":626,"categories":627,"draft":15,"wordCount":628,"readingTime":31,"canonical":629,"series":630},"\u002Fithome-2025-day-04","Day 4：掌握 LINE Bot 七種訊息類型與 NestJS 架構優化","目前我們都只使用 LINE Message Event 中的純文字(text)格式進行回覆，但除了純文字之外，LINE Bot 後端伺服器其實可以接收多種不同類型的訊息。今天就讓我們一起來深入了解這些訊息類型吧！","2025-09-17T22:53:37+08:00",[11,360,362,350],[11,362],5828,"https:\u002F\u002Fithelp.ithome.com.tw\u002Farticles\u002F10381651",{"name":366,"url":367,"day":134},{"path":632,"title":633,"description":634,"date":635,"updated":9,"tags":636,"categories":637,"draft":15,"wordCount":638,"readingTime":122,"canonical":639,"series":640},"\u002Fithome-2025-day-03","Day 3：Webhook 簽章驗證與訊息回覆策略(Push & Reply)","上一篇帶大家透過「Webhook 模式」成功架設了專屬的 LINE Bot 代理人。相信大家在體驗基礎功能後，對於 LINE Bot Webhook 還能監聽哪些事件、支援哪些類型的訊息回覆，以及如何確保後端收到的訊息確…","2025-09-16T21:53:39+08:00",[11,360,362,350],[11,362],5360,"https:\u002F\u002Fithelp.ithome.com.tw\u002Farticles\u002F10381303",{"name":366,"url":367,"day":318},{"path":642,"title":643,"description":644,"date":645,"updated":9,"tags":646,"categories":647,"draft":15,"wordCount":648,"readingTime":31,"canonical":649,"series":650},"\u002Fithome-2025-day-02","Day 2：從 Webhook 到後端，打造你的專屬機器人","上一篇，帶大家透過「Chat 模式」，讓自身變成客服機器人的方式。這篇會從「Webhook 模式」切入，並以 NestJS 作為後端框架，教你如何在休息時間，也能讓後端伺服器當你的替身幫你解惑使用者的問題。","2025-09-15T21:20:49+08:00",[11,360,362,350],[11,362],6590,"https:\u002F\u002Fithelp.ithome.com.tw\u002Farticles\u002F10380524",{"name":366,"url":367,"day":329},{"path":652,"title":653,"description":654,"date":655,"updated":9,"tags":656,"categories":657,"draft":15,"wordCount":658,"readingTime":318,"canonical":659,"series":660},"\u002Fithome-2025-day-01","Day 1：Hello World LINE Bot","每個程式語言的開始通常都會以練習 Hello World！作為一個簡單的起手式，LINE Bot 也不意外。這一系列會著重在 LINE Bot 的相關應用，帶大家用輕鬆的方式一起建立屬於自己的 Line Bot 聊天機器…","2025-09-14T22:48:33+08:00",[11,360,362,350],[11,362],2723,"https:\u002F\u002Fithelp.ithome.com.tw\u002Farticles\u002F10379895",{"name":366,"url":367,"day":340},{"path":662,"title":663,"description":664,"date":665,"updated":9,"tags":666,"categories":671,"draft":15,"wordCount":674,"readingTime":134,"canonical":9,"series":9},"\u002Fdbdiagram-tool","關聯式資料庫設計必備 - dbdiagram.io ERD 繪圖工具","還在煩惱如何設計關聯式資料表實體關聯圖嗎？ 使用 dbdiagram.io 加快你與同事之間的距離","2024-11-05T20:18:24+08:00",[667,668,669,670],"ERD","dbdiagram.io","DBML","資料庫設計",[672,673],"Database","開發工具",3982,{"path":676,"title":677,"description":678,"date":679,"updated":9,"tags":680,"categories":687,"draft":15,"wordCount":690,"readingTime":122,"canonical":9,"series":9},"\u002FPostgreSQL-1","前端勇士大闖六角後端體驗營 - 初探 PostgreSQL DML 語法","初步踏入後端的世界，了解何謂後端以及資料庫常見語法 DDL、DML。","2024-10-30T22:43:49+08:00",[681,682,683,684,685,686],"PostgreSQL","SQL","DML","DDL","資料庫","六角學院",[672,688,689],"後端實戰","學習心得",5220,{"path":692,"title":693,"description":694,"date":695,"updated":9,"tags":696,"categories":700,"draft":15,"wordCount":703,"readingTime":329,"canonical":9,"series":9},"\u002Fcss-flex-1","CSS flex 軸線對齊技巧 - 預設屬性","CSS flex 排版技巧你都了解了嗎？回歸學習初心的認識 flex 預設屬性","2024-10-24T20:29:08+08:00",[697,698,699],"Flexbox","前端排版","切版技巧",[701,702],"CSS","前端開發",1856,{"path":705,"title":706,"description":707,"date":708,"updated":9,"tags":709,"categories":712,"draft":15,"wordCount":714,"readingTime":329,"canonical":715,"series":716},"\u002Fithome-2024-day-30","Vue 3 用實作帶你看過核心概念 - Day 30：新手村的鐵人證書 - 完賽心得","花了整整半年左右的時間，每天下班都很用心的準備範例或是看書，這一段旅程對我來說真的很重要。擔心、害怕跟不安的心情一直充斥自己心中，擔心寫錯或是寫不好，想讓自己再多準備久一點再開始，所以拖到中秋連假才開始，想下定決心讓自己…","2024-10-13T12:42:25+08:00",[11,710,711],"2024 鐵人賽","Vue 3",[11,713],"Vue",1381,"https:\u002F\u002Fithelp.ithome.com.tw\u002Farticles\u002F10367206",{"name":717,"url":718,"day":22},"2024 iThome 鐵人賽：Vue 3 初學者：用實作帶你看過核心概念","https:\u002F\u002Fithelp.ithome.com.tw\u002Fusers\u002F20116554\u002Fironman\u002F7800",{"path":720,"title":721,"description":722,"date":723,"updated":9,"tags":724,"categories":727,"draft":15,"wordCount":728,"readingTime":134,"canonical":729,"series":730},"\u002Fithome-2024-day-29","Vue 3 用實作帶你看過核心概念 - Day 29：Composables(組合式函數)","Composables是 Vue 3 中的一個重要概念，它是利用 Vue 的 Composition API 來創建和管理可重用的有狀態邏輯的函數。Composables 允許我們將組件邏輯抽象成可重用的函數，使得代碼更…","2024-10-12T15:07:55+08:00",[11,710,711,725,726],"Options API","Composition API",[11,713],4233,"https:\u002F\u002Fithelp.ithome.com.tw\u002Farticles\u002F10366865",{"name":717,"url":718,"day":34},{"path":732,"title":733,"description":734,"date":735,"updated":9,"tags":736,"categories":738,"draft":15,"wordCount":739,"readingTime":134,"canonical":740,"series":741},"\u002Fithome-2024-day-28","Vue 3 用實作帶你看過核心概念 - Day 28：官方 Vue Router 的應用與技巧","路由設定方式，一般可以分成兩種：","2024-10-11T17:14:44+08:00",[11,710,711,725,737],"Vue Router",[11,713],4095,"https:\u002F\u002Fithelp.ithome.com.tw\u002Farticles\u002F10366520",{"name":717,"url":718,"day":45},{"path":743,"title":744,"description":745,"date":746,"updated":9,"tags":747,"categories":748,"draft":15,"wordCount":749,"readingTime":122,"canonical":750,"series":751},"\u002Fithome-2024-day-27","Vue 3 用實作帶你看過核心概念 - Day 27：VeeValidate 表單驗證工具","在開發 Vue 應用程式時，表單驗證至關重要，它能確保使用者輸入的資料符合預期的格式和要求。今天來介紹一款專門用於 Vue 的表單驗證工具—VeeValidate v4。這個工具不僅能幫助開發者輕鬆實現表單驗證，還提供了…","2024-10-10T21:02:16+08:00",[11,710,711,725],[11,713],4461,"https:\u002F\u002Fithelp.ithome.com.tw\u002Farticles\u002F10366165",{"name":717,"url":718,"day":56},{"path":753,"title":754,"description":755,"date":756,"updated":9,"tags":757,"categories":758,"draft":15,"wordCount":759,"readingTime":318,"canonical":760,"series":761},"\u002Fithome-2024-day-26","Vue 3 用實作帶你看過核心概念 - Day 26：KeepAlive 與 Teleport 內置組件","預設情況下，切換組件會導致組件的創建及銷毀，無法保持組件內部的狀態。","2024-10-09T18:50:53+08:00",[11,710,711,725],[11,713],3158,"https:\u002F\u002Fithelp.ithome.com.tw\u002Farticles\u002F10365724",{"name":717,"url":718,"day":67},{"path":763,"title":764,"description":765,"date":766,"updated":9,"tags":767,"categories":768,"draft":15,"wordCount":769,"readingTime":318,"canonical":770,"series":771},"\u002Fithome-2024-day-25","Vue 3 用實作帶你看過核心概念 - Day 25：自定義指令(Custom Directives)","Vue不僅提供了豐富的內置指令用於操作DOM元素，還允許開發者創建自定義指令。透過自定義指令，我們可以對DOM元素進行更細緻的控制，並在指令的不同生命週期階段執行特定的邏輯，從而實現更靈活的功能擴展。","2024-10-08T22:05:32+08:00",[11,710,711,725],[11,713],3116,"https:\u002F\u002Fithelp.ithome.com.tw\u002Farticles\u002F10365355",{"name":717,"url":718,"day":79},{"path":773,"title":774,"description":775,"date":776,"updated":9,"tags":777,"categories":778,"draft":15,"wordCount":779,"readingTime":329,"canonical":780,"series":781},"\u002Fithome-2024-day-24","Vue 3 用實作帶你看過核心概念 - Day 24：異步加載(Lazy loading)","在大型項目中，我們通常需要將應用拆分為更小的代碼模塊，並僅在需要時才從服務器加載相關組件，以減少初次加載的資源量。Vue 提供了 defineAsyncComponent 方法來實現組件的異步加載，這樣可以有效提高應用的…","2024-10-07T20:28:27+08:00",[11,710,711,725],[11,713],2171,"https:\u002F\u002Fithelp.ithome.com.tw\u002Farticles\u002F10364861",{"name":717,"url":718,"day":90},{"path":783,"title":784,"description":785,"date":786,"updated":9,"tags":787,"categories":788,"draft":15,"wordCount":789,"readingTime":318,"canonical":790,"series":791},"\u002Fithome-2024-day-23","Vue 3 用實作帶你看過核心概念 - Day 23：依賴注入( Provide-Inject )","在Dayxx中提到過，父子組件之間的數據傳遞可以通過props來實現。然而，當祖孫層組件需要進行數據傳遞時，中間層級的組件可能並不需要這個props，但卻不得不為了使子組件獲取數據而被迫傳遞。","2024-10-06T15:14:51+08:00",[11,710,711,725],[11,713],3183,"https:\u002F\u002Fithelp.ithome.com.tw\u002Farticles\u002F10364252",{"name":717,"url":718,"day":101},{"path":793,"title":794,"description":795,"date":796,"updated":9,"tags":797,"categories":798,"draft":15,"wordCount":799,"readingTime":134,"canonical":800,"series":801},"\u002Fithome-2024-day-22","Vue 3 用實作帶你看過核心概念 - Day 22：v-slot 插槽使用","先前Day 18中提到父組件可以通過props將參數資料傳遞給子組件進行渲染，這樣可以有效地將資料處理與畫面渲染的工作分開。然而，當我們需要更加客製化的呈現內容，由父組件來控制子組件的部分顯示時，可以使用v-slot 指…","2024-10-05T12:32:51+08:00",[11,710,711,725],[11,713],4292,"https:\u002F\u002Fithelp.ithome.com.tw\u002Farticles\u002F10363713",{"name":717,"url":718,"day":113},{"path":803,"title":804,"description":805,"date":806,"updated":9,"tags":807,"categories":808,"draft":15,"wordCount":809,"readingTime":329,"canonical":810,"series":811},"\u002Fithome-2024-day-21","Vue 3 用實作帶你看過核心概念 - Day 21： 組件透傳屬性(Attributes)的應用","當父組件向子組件傳遞屬性或監聽器，而這些屬性未在子組件中定義為props或emits時，它們會自動繼承並附加到子組件的根元素上，常見的屬性包括class、style、id等。這些屬性可以透過$attrs屬性訪問並進行操作…","2024-10-04T22:42:54+08:00",[11,710,711,725],[11,713],2146,"https:\u002F\u002Fithelp.ithome.com.tw\u002Farticles\u002F10363469",{"name":717,"url":718,"day":125},{"path":813,"title":814,"description":815,"date":816,"updated":9,"tags":817,"categories":818,"draft":15,"wordCount":819,"readingTime":122,"canonical":820,"series":821},"\u002Fithome-2024-day-20","Vue 3 用實作帶你看過核心概念 - Day 20：組件使用 v-model 雙向綁定","在Day 13中，我們介紹了表單元素（例如輸入框）如何處理數據雙向綁定。當需要將表單元素與一個響應式變數綁定時，v-model提供雙向綁定功能。這代表當畫面上表單元素的變動會即時影響Vue數據，同時當Vue數據的值改變時…","2024-10-03T23:40:48+08:00",[11,710,711,725],[11,713],5191,"https:\u002F\u002Fithelp.ithome.com.tw\u002Farticles\u002F10362957",{"name":717,"url":718,"day":137},{"path":823,"title":824,"description":825,"date":826,"updated":9,"tags":827,"categories":828,"draft":15,"wordCount":829,"readingTime":318,"canonical":830,"series":831},"\u002Fithome-2024-day-19","Vue 3 用實作帶你看過核心概念 - Day 19：子組件向父組件發射事件 - emits","組件可以通過$emit(functionName, params)自定義事件名稱並傳遞參數。自定義事件名稱建議使用kebab-case來命名自定義事件名稱，以確保命名風格與HTML 屬性一致性。此外，自定義事件還支持事件…","2024-10-02T15:51:16+08:00",[11,710,711,725],[11,713],2877,"https:\u002F\u002Fithelp.ithome.com.tw\u002Farticles\u002F10362144",{"name":717,"url":718,"day":148},{"path":833,"title":834,"description":835,"date":836,"updated":9,"tags":837,"categories":838,"draft":15,"wordCount":839,"readingTime":31,"canonical":840,"series":841},"\u002Fithome-2024-day-18","Vue 3 用實作帶你看過核心概念 - Day 18：父組件向子組件傳值 - props","組件之間的傳值必須透過聲明 props 的方式，這樣可以避免與HTML的屬性(attribute)混淆。父組件傳遞參數給子組件的方式有以下兩種方式：","2024-10-01T22:28:48+08:00",[11,710,711,725],[11,713],5782,"https:\u002F\u002Fithelp.ithome.com.tw\u002Farticles\u002F10361721",{"name":717,"url":718,"day":159},{"path":843,"title":844,"description":845,"date":846,"updated":9,"tags":847,"categories":848,"draft":15,"wordCount":849,"readingTime":318,"canonical":850,"series":851},"\u002Fithome-2024-day-17","Vue 3 用實作帶你看過核心概念 - Day 17：組件基礎 - 全局註冊與區域註冊","在 Day 5 我們提到可以將應用拆分為根組件和多個組件實例，並將功能模塊化。","2024-09-30T23:30:10+08:00",[11,710,711,725],[11,713],2954,"https:\u002F\u002Fithelp.ithome.com.tw\u002Farticles\u002F10361253",{"name":717,"url":718,"day":170},{"path":853,"title":854,"description":855,"date":856,"updated":9,"tags":857,"categories":858,"draft":15,"wordCount":859,"readingTime":122,"canonical":860,"series":861},"\u002Fithome-2024-day-16","Vue 3 用實作帶你看過核心概念 - Day 16：使用 ref 屬性引用模板元素","雖然 Vue 透過模板幫助我們處理了大部分的DOM 操作，但在某些情況下，仍然需要手動操作 DOM。例如，在使用第三方套件（如 Bootstrap 的 Modal）時，或者需要調用像video.play()和video.…","2024-09-29T16:25:45+08:00",[11,710,711,725],[11,713],4608,"https:\u002F\u002Fithelp.ithome.com.tw\u002Farticles\u002F10360419",{"name":717,"url":718,"day":181},{"path":863,"title":864,"description":865,"date":866,"updated":9,"tags":867,"categories":868,"draft":15,"wordCount":488,"readingTime":122,"canonical":869,"series":870},"\u002Fithome-2024-day-15","Vue 3 用實作帶你看過核心概念 - Day 15：監聽器(Watchers)","在響應式狀態變化時執行特定操作，需要使用watch 監聽器。這些操作可能包含副作用 (side effects)，如發送請求、調用 API，或更新 DOM 以外的系統狀態，亦或是處理自定義的邏輯。","2024-09-28T18:30:31+08:00",[11,710,711,725],[11,713],"https:\u002F\u002Fithelp.ithome.com.tw\u002Farticles\u002F10359958",{"name":717,"url":718,"day":192},{"path":872,"title":873,"description":874,"date":875,"updated":9,"tags":876,"categories":877,"draft":15,"wordCount":878,"readingTime":134,"canonical":879,"series":880},"\u002Fithome-2024-day-14","Vue 3 用實作帶你看過核心概念 - Day 14：生命週期鉤子(Lifecycle Hooks)","在 Vue 中，當一個組件創建時，它會經歷一系列的流程，這些流程決定了組件從初始化到渲染，再到最終銷毀的過程。","2024-09-27T21:57:32+08:00",[11,710,711,725],[11,713],3780,"https:\u002F\u002Fithelp.ithome.com.tw\u002Farticles\u002F10359419",{"name":717,"url":718,"day":203},{"path":882,"title":883,"description":884,"date":885,"updated":9,"tags":886,"categories":887,"draft":15,"wordCount":888,"readingTime":318,"canonical":889,"series":890},"\u002Fithome-2024-day-13","Vue 3 用實作帶你看過核心概念 - Day 13：v-model 雙向綁定控制 - 常用於表單輸入","表單輸入是開發中非常常見的需求，原始方式通常需要手動使用v-bind綁定表單元素的值 (value)，並透過v-on綁定input事件來監聽輸入變化。","2024-09-26T21:49:25+08:00",[11,710,711,725],[11,713],3153,"https:\u002F\u002Fithelp.ithome.com.tw\u002Farticles\u002F10358850",{"name":717,"url":718,"day":214},{"path":892,"title":893,"description":894,"date":895,"updated":9,"tags":896,"categories":897,"draft":15,"wordCount":898,"readingTime":134,"canonical":899,"series":900},"\u002Fithome-2024-day-12","Vue 3 用實作帶你看過核心概念 - Day 12：v-on 指令 - 事件處理","在 Vue 中，監聽 HTML DOM 元素的事件變化，可以使用v-on 指令將 JavaScript 事件處理器綁定到對應的DOM 事件上。這個指令的縮寫符號為@，例如：v-on:click，其縮寫方式為@click。","2024-09-25T21:42:59+08:00",[11,710,711,725],[11,713],3808,"https:\u002F\u002Fithelp.ithome.com.tw\u002Farticles\u002F10358241",{"name":717,"url":718,"day":225},{"path":902,"title":903,"description":904,"date":905,"updated":9,"tags":906,"categories":907,"draft":15,"wordCount":908,"readingTime":134,"canonical":909,"series":910},"\u002Fithome-2024-day-11","Vue 3 用實作帶你看過核心概念 - Day 11：v-for 指令的基本與進階應用","當數據類型是陣列或物件時，我們不會希望將重複的選項或元素直接硬編碼在模板中。這樣的寫法會導致代碼冗長且不具可維護性。","2024-09-24T23:11:25+08:00",[11,710,711,725],[11,713],4381,"https:\u002F\u002Fithelp.ithome.com.tw\u002Farticles\u002F10357705",{"name":717,"url":718,"day":236},{"path":912,"title":913,"description":914,"date":915,"updated":9,"tags":916,"categories":917,"draft":15,"wordCount":918,"readingTime":318,"canonical":919,"series":920},"\u002Fithome-2024-day-10","Vue 3 用實作帶你看過核心概念 - Day 10：條件渲染 - v-if 與 v-show 的區別與應用","開發中遇到需要處理【如果是...就要...】的情境時，Vue 提供了 v-if 指令來幫助我們根據條件進行元素的渲染。這樣可以在特定條件滿足時動態地顯示或隱藏某些元素。","2024-09-23T23:39:24+08:00",[11,710,711,725],[11,713],2827,"https:\u002F\u002Fithelp.ithome.com.tw\u002Farticles\u002F10357160",{"name":717,"url":718,"day":247},{"path":922,"title":923,"description":924,"date":925,"updated":9,"tags":926,"categories":927,"draft":15,"wordCount":928,"readingTime":122,"canonical":929,"series":930},"\u002Fithome-2024-day-09","Vue 3 用實作帶你看過核心概念 - Day 9：Class 與 Style 的樣式綁定","v-bind 指令通常用於綁定 HTML 屬性，但在實際開發中，最常見的應用場景之一還是綁定class和 style這兩個 HTML 屬性。","2024-09-22T15:05:53+08:00",[11,710,711,725],[11,713],4630,"https:\u002F\u002Fithelp.ithome.com.tw\u002Farticles\u002F10356119",{"name":717,"url":718,"day":76},{"path":932,"title":933,"description":934,"date":935,"updated":9,"tags":936,"categories":937,"draft":15,"wordCount":938,"readingTime":134,"canonical":939,"series":940},"\u002Fithome-2024-day-08","Vue 3 用實作帶你看過核心概念 - Day 8：計算屬性應用與實踐","在 Day 6 在使用 Vue 的Mustache語法時，可以用來放置表達式。不過，這邊建議避免在 Mustache 中撰寫過於複雜的邏輯。這樣的建議主要有兩個原因：","2024-09-21T21:33:29+08:00",[11,710,711,725],[11,713],4060,"https:\u002F\u002Fithelp.ithome.com.tw\u002Farticles\u002F10355474",{"name":717,"url":718,"day":110},{"path":942,"title":943,"description":944,"date":945,"updated":9,"tags":946,"categories":947,"draft":15,"wordCount":948,"readingTime":122,"canonical":949,"series":950},"\u002Fithome-2024-day-07","Vue 3 用實作帶你看過核心概念 - Day 7： 響應式基礎 - Options API","前面提到了模板搭配指令及 Mustache 的用法。今天則是要介紹所謂透過getter跟setter取值跟賦值的方式在 JavaScript 是怎麼做到的，這部分會跟 Vue 本身的響應式基礎有很大相關。此外，我也會帶著…","2024-09-20T23:41:42+08:00",[11,710,711],[11,713],4407,"https:\u002F\u002Fithelp.ithome.com.tw\u002Farticles\u002F10354781",{"name":717,"url":718,"day":17},{"path":952,"title":953,"description":954,"date":955,"updated":9,"tags":956,"categories":957,"draft":15,"wordCount":958,"readingTime":134,"canonical":959,"series":960},"\u002Fithome-2024-day-06","Vue 3 用實作帶你看過核心概念 - Day 6：數據綁定和模板(Template)","Vue 使用基於 HTML 的模板語法（Template Syntax），將 Vue 實例中的數據綁定到模板中進行顯示。根據綁定的類型不同，數據可以影響元素的內容、屬性或樣式。","2024-09-19T20:39:46+08:00",[11,710,711,725],[11,713],3402,"https:\u002F\u002Fithelp.ithome.com.tw\u002Farticles\u002F10354231",{"name":717,"url":718,"day":31},{"path":962,"title":963,"description":964,"date":965,"updated":9,"tags":966,"categories":967,"draft":15,"wordCount":968,"readingTime":318,"canonical":969,"series":970},"\u002Fithome-2024-day-05","Vue 3 用實作帶你看過核心概念 - Day 5：Options API vs Composition API","前面已經詳細說明了 Vue 的環境建置方式，接下來將逐步介紹 Vue 應用說明，並比較Options API與Composition API的撰寫風格。","2024-09-18T22:10:36+08:00",[11,710,711,725,726],[11,713],2902,"https:\u002F\u002Fithelp.ithome.com.tw\u002Farticles\u002F10353717",{"name":717,"url":718,"day":122},{"path":972,"title":973,"description":974,"date":975,"updated":9,"tags":976,"categories":977,"draft":15,"wordCount":658,"readingTime":318,"canonical":978,"series":979},"\u002Fithome-2024-day-04","Vue 3 用實作帶你看過核心概念 - Day 4：基於 Vite 建構工具的 Vue 專案結構解析","在 Day 3 的教學中，學習了如何使用 Vue 鷹架工具(Vue project scaffolding tool)來生成一個基於 Vite 環境的專案。今天，我將更進一步地解析這個專案的資料夾結構，幫助大家更好地理解…","2024-09-17T23:27:07+08:00",[11,710,711,725],[11,713],"https:\u002F\u002Fithelp.ithome.com.tw\u002Farticles\u002F10352470",{"name":717,"url":718,"day":134},{"path":981,"title":982,"description":983,"date":984,"updated":9,"tags":985,"categories":986,"draft":15,"wordCount":987,"readingTime":329,"canonical":988,"series":989},"\u002Fithome-2024-day-03","Vue 3 用實作帶你看過核心概念 - Day 3：使用 Vite 建構工具搭建 Vue 專案","⭐ 需要特別注意，需要事先安裝Nodejs。若不確定是否已安裝 Nodejs 也可以開啟終端機，執行以下指令確認版本。","2024-09-16T23:29:45+08:00",[11,710,711,725],[11,713],2100,"https:\u002F\u002Fithelp.ithome.com.tw\u002Farticles\u002F10351398",{"name":717,"url":718,"day":318},{"path":991,"title":992,"description":993,"date":994,"updated":9,"tags":995,"categories":996,"draft":15,"wordCount":997,"readingTime":329,"canonical":998,"series":999},"\u002Fithome-2024-day-02","Vue 3 用實作帶你看過核心概念 - Day 2：命令式編程 vs 聲明式編程","還記得我們在使用純 HTML 和 JavaScript 時，如何實現按下按鈕來變更文字顏色嗎？讓我們一起回想一下什麼是命令式宣告。","2024-09-15T22:52:27+08:00",[11,710,711,725,726],[11,713],1881,"https:\u002F\u002Fithelp.ithome.com.tw\u002Farticles\u002F10350459",{"name":717,"url":718,"day":329},{"path":1001,"title":1002,"description":1003,"date":1004,"updated":9,"tags":1005,"categories":1006,"draft":15,"wordCount":1007,"readingTime":340,"canonical":1008,"series":1009},"\u002Fithome-2024-day-01","Vue 3 用實作帶你看過核心概念 - Day 1：前言介紹","大家好，我是 Antonio(安東尼奧)，目前是一名 Angular 的新手工程師，同時，也是一名熱愛寫程式的工程師。去年參加六角學院的 Vue 直播班，在那時候就深深著迷著 Vue 的語言，自此這半年多的時間裡，我白天…","2024-09-14T17:32:19+08:00",[11,710,711],[11,713],988,"https:\u002F\u002Fithelp.ithome.com.tw\u002Farticles\u002F10350457",{"name":717,"url":718,"day":340},{"path":1011,"title":1012,"description":1013,"date":1014,"updated":9,"tags":1015,"categories":1017,"draft":15,"wordCount":1019,"readingTime":329,"canonical":9,"series":9},"\u002Fhexschool-experience","六角學院 - 軟體工程師體驗營","這麼多線上課程? 你不想知道什麼是最吸引我的線上學習課程嗎?","2024-05-31T21:40:05+08:00",[686,1016],"軟體工程師體驗營",[689,1018],"前端成長記",1109,{"path":1021,"title":1022,"description":1023,"date":1024,"updated":9,"tags":1025,"categories":1033,"draft":15,"wordCount":1035,"readingTime":318,"canonical":9,"series":9},"\u002FJS-10","JavaScript：var、let、const之間的差異解析","var、let及const是JavaScript中宣告變數的關鍵字，它們在作用域、對於for迴圈的影響、提升 (Hoisting) 的差異及重複宣告的處理上有所不同。","2023-12-10T23:53:30+08:00",[1026,1027,1028,1029,1030,1031,1032],"ES6","var","let","const","Hoisting","Scope","TDZ",[1034,702],"JavaScript",2873,{"path":1037,"title":1038,"description":1039,"date":1040,"updated":9,"tags":1041,"categories":1048,"draft":15,"wordCount":1049,"readingTime":122,"canonical":9,"series":9},"\u002FJS-9","JavaScript：陣列的常見操作方法","掌握 JavaScript 陣列操作！從forEach、map、filter、findIndex、reduce、sort，深入了解這些方法，使你的程式碼更具靈活性和效率！","2023-12-01T15:01:06+08:00",[1042,1043,1044,1045,1046,1047],"forEach","map","filter","reduce","sort","findIndex",[1034,702],4846,{"path":1051,"title":1052,"description":1053,"date":1054,"updated":9,"tags":1055,"categories":1060,"draft":15,"wordCount":1061,"readingTime":318,"canonical":9,"series":9},"\u002FJS-8","JavaScript：ES module 匯入與匯出","使用\u003C script >標籤讓瀏覽器中的網頁能夠使用 ES 模組功能時，你了解不同的匯入及匯出方法了嗎？","2023-11-30T15:28:23+08:00",[1026,1056,1057,1058,1059],"ES Module","CommonJS","Node.js","模組化開發",[1034,702],2913,{"path":1063,"title":1064,"description":1065,"date":1066,"updated":9,"tags":1067,"categories":1070,"draft":15,"wordCount":1072,"readingTime":134,"canonical":9,"series":9},"\u002FReact-2","React：JSX 是什麼？為何在 React 中使用 JSX？","透過 JSX 語法糖，你能夠在一次 JavaScript 撰寫中包含 HTML 與 CSS 的內容","2023-11-29T16:03:40+08:00",[1068,1034,1069],"JSX","Babel",[1071,702],"React",3595,{"path":1074,"title":1075,"description":1076,"date":1077,"updated":9,"tags":1078,"categories":1081,"draft":15,"wordCount":1082,"readingTime":329,"canonical":9,"series":9},"\u002FReact-1","React：Pure Function 的概念及其在 React 中的應用","探索 Pure Function 概念及其與 React 的相互關係。","2023-11-29T15:50:17+08:00",[1034,1079,1080],"Pure Function","Functional Programming",[1071],1368,{"path":1084,"title":1085,"description":1086,"date":1087,"updated":9,"tags":1088,"categories":1093,"draft":15,"wordCount":1094,"readingTime":122,"canonical":9,"series":9},"\u002FJS-6","JavaScript：深入理解Promise的原理及實際應用","透過Promise，我們能夠有效解決JavaScript中的異步事件，使得程式碼更為清晰和可讀。","2023-11-29T14:49:18+08:00",[1089,1090,1091,1092],"Promise","AsyncAwait","Asynchronous Programming","異步處理",[1034,702],5479,{"path":1096,"title":1097,"description":1098,"date":1099,"updated":9,"tags":1100,"categories":1105,"draft":15,"wordCount":1106,"readingTime":122,"canonical":9,"series":9},"\u002FJS-5","JavaScript：物件傳參考特性(Pass by Reference)","淺拷貝(shallow copy)與深拷貝(deep copy)在JavaScript中的應用與理解","2023-11-29T09:55:50+08:00",[1101,1102,1103,1104],"Pass by Reference","Shallow Copy","Deep Copy","傳值與傳參考",[1034,702],4544,{"path":1108,"title":1109,"description":1110,"date":1111,"updated":9,"tags":1112,"categories":1118,"draft":15,"wordCount":1120,"readingTime":329,"canonical":9,"series":9},"\u002FJS-4","JavaScript：注重關注點的分離","透過關注點分離的設計方式，可顯著提高系統整體的可維護性。","2023-11-29T09:44:29+08:00",[1113,1114,1115,1116,1117],"SoC","MVC","Design Patterns","Clean Code","Refactoring",[1034,1119],"Software Engineering",1977,{"path":1122,"title":1123,"description":1124,"date":1125,"updated":9,"tags":1126,"categories":1132,"draft":15,"wordCount":1133,"readingTime":329,"canonical":9,"series":9},"\u002FJS-3","JavaScript：掌握箭頭函式，優雅簡約的程式寫作","深入解析ES6箭頭函數：揭開與傳統函式的差異。","2023-11-29T01:02:36+08:00",[1127,1128,1129,1130,1131],"Arrow Function","this","Lexical Scoping","Syntactic Sugar","Callback Function",[1034,702],2142,{"path":1135,"title":1136,"description":1137,"date":1138,"updated":9,"tags":1139,"categories":1143,"draft":15,"wordCount":1144,"readingTime":329,"canonical":9,"series":9},"\u002FJS-2","JavaScript：深入了解This的指向與應用","探索JavaScript This 的指向：深入剖析判斷的技巧。","2023-11-28T22:22:45+08:00",[1128,1140,1131,1141,1142],"Execution Context","Binding","Fundamentals",[1034,702],1963,{"path":1146,"title":1147,"description":1148,"date":1149,"updated":9,"tags":1150,"categories":1154,"draft":15,"wordCount":1155,"readingTime":340,"canonical":9,"series":9},"\u002FJS-1","JavaScript：淺談ES6常見縮寫","JavaScript ES6縮寫技巧：輕鬆簡化程式碼，提升效率！。","2023-11-28T13:38:14+08:00",[1026,1151,1152,1153],"Shorthand","Spread Operator","Object",[1034,702],818,{"path":1157,"title":1158,"description":1159,"date":1160,"updated":9,"tags":1161,"categories":1165,"draft":15,"wordCount":1166,"readingTime":340,"canonical":9,"series":9},"\u002FEmmet-1","前端開發神器：使用Emmet提升網頁開發效率","本文將介紹如何利用Emmet來大幅提高前端開發效率，讓你的編碼速度如專家般飛快。","2023-10-31T14:40:54+08:00",[1162,1163,1164],"Emmet","VSCode","HTML",[702,673],865,{"path":1168,"title":1169,"description":1170,"date":1171,"updated":9,"tags":1172,"categories":1177,"draft":15,"wordCount":1179,"readingTime":340,"canonical":9,"series":9},"\u002Fhexo-github-4","建立自己的部落格：了解Hexo指令，更換next部落格主題","今天的你跟我都是Hexo指令指揮官，讓我們將部落格造型大改造一下吧!!!","2023-10-20T14:33:38+08:00",[1173,1174,1175,1176],"Hexo","NexT","git clone","Hexo指令",[1178],"Blog",979,{"path":1181,"title":1182,"description":1183,"date":1184,"updated":9,"tags":1185,"categories":1189,"draft":15,"wordCount":1190,"readingTime":329,"canonical":9,"series":9},"\u002Fhexo-github-3","建立自己的部落格：修改Hexo設定檔中Site，查看其變化","今天的你跟我都是部落格工程師，我們一起來將網頁做一些小小的改變，有一天匯集在一起就會讓你的部落格變的與眾不同。","2023-10-18T20:50:31+08:00",[1173,1163,1186,1187,1188],"Sublime Text","YAML","SEO",[1178],1798,{"path":1192,"title":1193,"description":1194,"date":1195,"updated":9,"tags":1196,"categories":1199,"draft":15,"wordCount":1200,"readingTime":340,"canonical":9,"series":9},"\u002Fhexo-github-2","建立自己的部落格：創建Hexo Blog初始的模板","踏出那關鍵的第一步，從白紙到完整的部落格，一同見證你的部落格誕生的奇妙時刻。","2023-10-17T15:59:37+08:00",[1173,1197,1198],"Hexo-cli","hexo init",[1178],941,{"path":1202,"title":1203,"description":1204,"date":1205,"updated":9,"tags":1206,"categories":1208,"draft":15,"wordCount":1209,"readingTime":340,"canonical":9,"series":9},"\u002Fhexo-github-1","建立自己的部落格：認識Hexo及所其需工具(Nodejs & Git)","打造屬於自己風格的部落格其實不難，讓我們一步步手把手教你如何實現這個目標。","2023-10-16T08:30:27+08:00",[1173,1058,1207],"Git",[1178],790,{"id":1211,"title":854,"body":1212,"canonical":860,"categories":3952,"date":856,"description":855,"draft":15,"extension":3953,"meta":3954,"navigation":1736,"ogImage":9,"path":853,"rawbody":3955,"readingTime":122,"robots":9,"schemaOrg":9,"seo":3956,"series":3957,"sitemap":3958,"slug":3963,"stem":3964,"tags":3965,"updated":9,"wordCount":859,"__hash__":3966},"posts\u002F2024-09-29-ithome-2024-day-16.md",{"type":1213,"value":1214,"toc":3942},"minimark",[1215,1223,1227,1249,1252,1256,1284,1303,1306,1326,1336,1339,1686,1689,1886,1888,1891,1898,1925,1928,2324,2326,2481,2495,2499,2516,2523,2525,2682,2684,2844,2847,2865,2872,2874,2931,2933,3028,3035,3038,3052,3055,3067,3074,3080,3082,3196,3198,3316,3319,3345,3347,3355,3361,3368,3371,3461,3476,3479,3605,3608,3709,3711,3721,3734,3746,3753,3755,3856,3859,3938],[1216,1217,1218],"p",{},[1219,1220],"img",{"alt":1221,"src":1222},"文章背景圖","https:\u002F\u002Fres.cloudinary.com\u002Fdseg0uwc9\u002Fimage\u002Fupload\u002Fv1727592415\u002F2024%20%E9%90%B5%E4%BA%BA%E8%B3%BD\u002FDay%2016%EF%BC%9A%E6%A8%A1%E6%9D%BF%E5%BC%95%E7%94%A8%28ref%29\u002FDay_16_%E4%BD%BF%E7%94%A8_ref_%E5%B1%AC%E6%80%A7%E5%BC%95%E7%94%A8%E6%A8%A1%E6%9D%BF%E5%85%83%E7%B4%A0_vgnlzg.png",[1224,1225,1226],"h2",{"id":1226},"目錄",[1228,1229,1230,1234,1237,1240,1243,1246],"ul",{},[1231,1232,1233],"li",{},"ref 屬性搭配第三方 Boostrap Modal 使用",[1231,1235,1236],{},"ref 屬性搭配 Video Web API 使用",[1231,1238,1239],{},"v-for 搭配陣列儲存 ref 屬性使用",[1231,1241,1242],{},"動態 ref 屬性綁定方法",[1231,1244,1245],{},"組件實例搭配 ref 使用",[1231,1247,1248],{},"總結",[1250,1251],"hr",{},[1253,1254,1233],"h3",{"id":1255},"ref-屬性搭配第三方-boostrap-modal-使用",[1216,1257,1258,1259,1263,1264,1267,1268,1271,1272,1275,1276,1279,1280,1283],{},"雖然 Vue 透過模板幫助我們處理了大部分的",[1260,1261,1262],"code",{},"DOM 操作","，但在某些情況下，仍然需要手動操作 DOM。例如，在使用第三方套件（如 Bootstrap 的 Modal）時，或者需要調用像",[1260,1265,1266],{},"video.play()","和",[1260,1269,1270],{},"video.pause()","這類的",[1260,1273,1274],{},"原生 Web API"," 時，我們必須直接與 DOM 元素進行交互。此時，可以使用",[1260,1277,1278],{},"ref","屬性為",[1260,1281,1282],{},"DOM 元素設置標記","，以便方便地引用並手動操作這些元素。",[1216,1285,1286,1287,1290,1291,1294,1295,1298,1299,1302],{},"觀察",[1260,1288,1289],{},"Bootstrap","的",[1260,1292,1293],{},"Modal 組件","可以發現，若要使用 JavaScript 來控制 Modal，需要先創建一個 Bootstrap Modal 的實例，並將對應的 Modal 元素 ID 傳遞給這個實例。完成這一步後，就可以透過 ",[1260,1296,1297],{},"modal.show()","或",[1260,1300,1301],{},"modal.hide()","這樣的方法來控制 Modal 的開啟和關閉。",[1216,1304,1305],{},"原生的 Boostrap Modal 使用流程說明：",[1307,1308,1309,1316],"ol",{},[1231,1310,1311,1312,1315],{},"初始化透過",[1260,1313,1314],{},"Boostrap","實例綁定對應顯示的 Modal DOM 元素。",[1231,1317,1318,1319,1267,1322,1325],{},"監聽 Modal 內的儲存(Save)按鈕跟關閉(Close)按鈕，點擊的時候觸發對應的方法",[1260,1320,1321],{},"show()",[1260,1323,1324],{},"hide()","方法。",[1216,1327,1328,1329],{},"👉 ",[1330,1331,1335],"a",{"href":1332,"rel":1333},"https:\u002F\u002Fcodepen.io\u002Fgwhvusel-the-builder\u002Fpen\u002FXWLBXgX",[1334],"nofollow","Boostrap Modal 純 javaScript 寫法實作連結",[1216,1337,1338],{},"HTML：",[1340,1341,1346],"pre",{"className":1342,"code":1343,"language":1344,"meta":1345,"style":1345},"language-html shiki shiki-themes github-light github-dark-dimmed","  \u003Cdiv class=\"modal\" tabindex=\"-1\" role=\"dialog\" id=\"modal\">\n    \u003Cdiv class=\"modal-dialog\" role=\"document\">\n      \u003Cdiv class=\"modal-content\">\n        \u003Cdiv class=\"modal-header\">\n          \u003Ch5 class=\"modal-title\">Modal title\u003C\u002Fh5>\n          \u003Cbutton type=\"button\" class=\"btn-close\" data-bs-dismiss=\"modal\" aria-label=\"Close\">\u003C\u002Fbutton>\n        \u003C\u002Fdiv>\n        \u003Cdiv class=\"modal-body\">\n          \u003Cp>Modal body text goes here.\u003C\u002Fp>\n        \u003C\u002Fdiv>\n        \u003Cdiv class=\"modal-footer\">\n          \u003Cbutton id=\"saveButton\" type=\"button\" class=\"btn btn-primary\">Save changes\u003C\u002Fbutton>\n          \u003Cbutton id=\"closeButton\" type=\"button\" class=\"btn btn-secondary\" data-dismiss=\"modal\">Close\u003C\u002Fbutton>\n        \u003C\u002Fdiv>\n      \u003C\u002Fdiv>\n    \u003C\u002Fdiv>\n  \u003C\u002Fdiv>\n","html","",[1260,1347,1348,1397,1420,1436,1452,1474,1518,1527,1542,1555,1563,1578,1611,1651,1659,1668,1677],{"__ignoreMap":1345},[1349,1350,1352,1356,1360,1364,1367,1371,1374,1376,1379,1382,1384,1387,1390,1392,1394],"span",{"class":1351,"line":340},"line",[1349,1353,1355],{"class":1354},"sYgZi","  \u003C",[1349,1357,1359],{"class":1358},"sIAta","div",[1349,1361,1363],{"class":1362},"sMOND"," class",[1349,1365,1366],{"class":1354},"=",[1349,1368,1370],{"class":1369},"s-HuK","\"modal\"",[1349,1372,1373],{"class":1362}," tabindex",[1349,1375,1366],{"class":1354},[1349,1377,1378],{"class":1369},"\"-1\"",[1349,1380,1381],{"class":1362}," role",[1349,1383,1366],{"class":1354},[1349,1385,1386],{"class":1369},"\"dialog\"",[1349,1388,1389],{"class":1362}," id",[1349,1391,1366],{"class":1354},[1349,1393,1370],{"class":1369},[1349,1395,1396],{"class":1354},">\n",[1349,1398,1399,1402,1404,1406,1408,1411,1413,1415,1418],{"class":1351,"line":329},[1349,1400,1401],{"class":1354},"    \u003C",[1349,1403,1359],{"class":1358},[1349,1405,1363],{"class":1362},[1349,1407,1366],{"class":1354},[1349,1409,1410],{"class":1369},"\"modal-dialog\"",[1349,1412,1381],{"class":1362},[1349,1414,1366],{"class":1354},[1349,1416,1417],{"class":1369},"\"document\"",[1349,1419,1396],{"class":1354},[1349,1421,1422,1425,1427,1429,1431,1434],{"class":1351,"line":318},[1349,1423,1424],{"class":1354},"      \u003C",[1349,1426,1359],{"class":1358},[1349,1428,1363],{"class":1362},[1349,1430,1366],{"class":1354},[1349,1432,1433],{"class":1369},"\"modal-content\"",[1349,1435,1396],{"class":1354},[1349,1437,1438,1441,1443,1445,1447,1450],{"class":1351,"line":134},[1349,1439,1440],{"class":1354},"        \u003C",[1349,1442,1359],{"class":1358},[1349,1444,1363],{"class":1362},[1349,1446,1366],{"class":1354},[1349,1448,1449],{"class":1369},"\"modal-header\"",[1349,1451,1396],{"class":1354},[1349,1453,1454,1457,1460,1462,1464,1467,1470,1472],{"class":1351,"line":122},[1349,1455,1456],{"class":1354},"          \u003C",[1349,1458,1459],{"class":1358},"h5",[1349,1461,1363],{"class":1362},[1349,1463,1366],{"class":1354},[1349,1465,1466],{"class":1369},"\"modal-title\"",[1349,1468,1469],{"class":1354},">Modal title\u003C\u002F",[1349,1471,1459],{"class":1358},[1349,1473,1396],{"class":1354},[1349,1475,1476,1478,1481,1484,1486,1489,1491,1493,1496,1499,1501,1503,1506,1508,1511,1514,1516],{"class":1351,"line":31},[1349,1477,1456],{"class":1354},[1349,1479,1480],{"class":1358},"button",[1349,1482,1483],{"class":1362}," type",[1349,1485,1366],{"class":1354},[1349,1487,1488],{"class":1369},"\"button\"",[1349,1490,1363],{"class":1362},[1349,1492,1366],{"class":1354},[1349,1494,1495],{"class":1369},"\"btn-close\"",[1349,1497,1498],{"class":1362}," data-bs-dismiss",[1349,1500,1366],{"class":1354},[1349,1502,1370],{"class":1369},[1349,1504,1505],{"class":1362}," aria-label",[1349,1507,1366],{"class":1354},[1349,1509,1510],{"class":1369},"\"Close\"",[1349,1512,1513],{"class":1354},">\u003C\u002F",[1349,1515,1480],{"class":1358},[1349,1517,1396],{"class":1354},[1349,1519,1520,1523,1525],{"class":1351,"line":17},[1349,1521,1522],{"class":1354},"        \u003C\u002F",[1349,1524,1359],{"class":1358},[1349,1526,1396],{"class":1354},[1349,1528,1529,1531,1533,1535,1537,1540],{"class":1351,"line":110},[1349,1530,1440],{"class":1354},[1349,1532,1359],{"class":1358},[1349,1534,1363],{"class":1362},[1349,1536,1366],{"class":1354},[1349,1538,1539],{"class":1369},"\"modal-body\"",[1349,1541,1396],{"class":1354},[1349,1543,1544,1546,1548,1551,1553],{"class":1351,"line":76},[1349,1545,1456],{"class":1354},[1349,1547,1216],{"class":1358},[1349,1549,1550],{"class":1354},">Modal body text goes here.\u003C\u002F",[1349,1552,1216],{"class":1358},[1349,1554,1396],{"class":1354},[1349,1556,1557,1559,1561],{"class":1351,"line":247},[1349,1558,1522],{"class":1354},[1349,1560,1359],{"class":1358},[1349,1562,1396],{"class":1354},[1349,1564,1565,1567,1569,1571,1573,1576],{"class":1351,"line":236},[1349,1566,1440],{"class":1354},[1349,1568,1359],{"class":1358},[1349,1570,1363],{"class":1362},[1349,1572,1366],{"class":1354},[1349,1574,1575],{"class":1369},"\"modal-footer\"",[1349,1577,1396],{"class":1354},[1349,1579,1580,1582,1584,1586,1588,1591,1593,1595,1597,1599,1601,1604,1607,1609],{"class":1351,"line":225},[1349,1581,1456],{"class":1354},[1349,1583,1480],{"class":1358},[1349,1585,1389],{"class":1362},[1349,1587,1366],{"class":1354},[1349,1589,1590],{"class":1369},"\"saveButton\"",[1349,1592,1483],{"class":1362},[1349,1594,1366],{"class":1354},[1349,1596,1488],{"class":1369},[1349,1598,1363],{"class":1362},[1349,1600,1366],{"class":1354},[1349,1602,1603],{"class":1369},"\"btn btn-primary\"",[1349,1605,1606],{"class":1354},">Save changes\u003C\u002F",[1349,1608,1480],{"class":1358},[1349,1610,1396],{"class":1354},[1349,1612,1613,1615,1617,1619,1621,1624,1626,1628,1630,1632,1634,1637,1640,1642,1644,1647,1649],{"class":1351,"line":214},[1349,1614,1456],{"class":1354},[1349,1616,1480],{"class":1358},[1349,1618,1389],{"class":1362},[1349,1620,1366],{"class":1354},[1349,1622,1623],{"class":1369},"\"closeButton\"",[1349,1625,1483],{"class":1362},[1349,1627,1366],{"class":1354},[1349,1629,1488],{"class":1369},[1349,1631,1363],{"class":1362},[1349,1633,1366],{"class":1354},[1349,1635,1636],{"class":1369},"\"btn btn-secondary\"",[1349,1638,1639],{"class":1362}," data-dismiss",[1349,1641,1366],{"class":1354},[1349,1643,1370],{"class":1369},[1349,1645,1646],{"class":1354},">Close\u003C\u002F",[1349,1648,1480],{"class":1358},[1349,1650,1396],{"class":1354},[1349,1652,1653,1655,1657],{"class":1351,"line":203},[1349,1654,1522],{"class":1354},[1349,1656,1359],{"class":1358},[1349,1658,1396],{"class":1354},[1349,1660,1661,1664,1666],{"class":1351,"line":192},[1349,1662,1663],{"class":1354},"      \u003C\u002F",[1349,1665,1359],{"class":1358},[1349,1667,1396],{"class":1354},[1349,1669,1670,1673,1675],{"class":1351,"line":181},[1349,1671,1672],{"class":1354},"    \u003C\u002F",[1349,1674,1359],{"class":1358},[1349,1676,1396],{"class":1354},[1349,1678,1679,1682,1684],{"class":1351,"line":170},[1349,1680,1681],{"class":1354},"  \u003C\u002F",[1349,1683,1359],{"class":1358},[1349,1685,1396],{"class":1354},[1216,1687,1688],{},"javascript：",[1340,1690,1694],{"className":1691,"code":1692,"language":1693,"meta":1345,"style":1345},"language-javascript shiki shiki-themes github-light github-dark-dimmed","const myModal = new bootstrap.Modal(document.getElementById(\"modal\"));\n\n\u002F\u002F 開啟 Modal 按鈕\ndocument.querySelector(\"#openModal\").addEventListener(\"click\", function () {\n  myModal.show();\n});\n\n\u002F\u002F Modal 儲存按鈕\ndocument.querySelector(\"#saveButton\").addEventListener(\"click\", function () {\n  myModal.hide();\n});\n\n\u002F\u002F Modal 關閉按鈕\ndocument.querySelector(\"#closeButton\").addEventListener(\"click\", function () {\n  myModal.hide();\n});\n","javascript",[1260,1695,1696,1732,1738,1744,1777,1788,1793,1797,1802,1827,1836,1840,1844,1849,1874,1882],{"__ignoreMap":1345},[1349,1697,1698,1701,1705,1708,1711,1714,1718,1721,1724,1727,1729],{"class":1351,"line":340},[1349,1699,1029],{"class":1700},"s7YZ4",[1349,1702,1704],{"class":1703},"sviXB"," myModal",[1349,1706,1707],{"class":1700}," =",[1349,1709,1710],{"class":1700}," new",[1349,1712,1713],{"class":1354}," bootstrap.",[1349,1715,1717],{"class":1716},"sPO5f","Modal",[1349,1719,1720],{"class":1354},"(document.",[1349,1722,1723],{"class":1716},"getElementById",[1349,1725,1726],{"class":1354},"(",[1349,1728,1370],{"class":1369},[1349,1730,1731],{"class":1354},"));\n",[1349,1733,1734],{"class":1351,"line":329},[1349,1735,1737],{"emptyLinePlaceholder":1736},true,"\n",[1349,1739,1740],{"class":1351,"line":318},[1349,1741,1743],{"class":1742},"sDN9O","\u002F\u002F 開啟 Modal 按鈕\n",[1349,1745,1746,1749,1752,1754,1757,1760,1763,1765,1768,1771,1774],{"class":1351,"line":134},[1349,1747,1748],{"class":1354},"document.",[1349,1750,1751],{"class":1716},"querySelector",[1349,1753,1726],{"class":1354},[1349,1755,1756],{"class":1369},"\"#openModal\"",[1349,1758,1759],{"class":1354},").",[1349,1761,1762],{"class":1716},"addEventListener",[1349,1764,1726],{"class":1354},[1349,1766,1767],{"class":1369},"\"click\"",[1349,1769,1770],{"class":1354},", ",[1349,1772,1773],{"class":1700},"function",[1349,1775,1776],{"class":1354}," () {\n",[1349,1778,1779,1782,1785],{"class":1351,"line":122},[1349,1780,1781],{"class":1354},"  myModal.",[1349,1783,1784],{"class":1716},"show",[1349,1786,1787],{"class":1354},"();\n",[1349,1789,1790],{"class":1351,"line":31},[1349,1791,1792],{"class":1354},"});\n",[1349,1794,1795],{"class":1351,"line":17},[1349,1796,1737],{"emptyLinePlaceholder":1736},[1349,1798,1799],{"class":1351,"line":110},[1349,1800,1801],{"class":1742},"\u002F\u002F Modal 儲存按鈕\n",[1349,1803,1804,1806,1808,1810,1813,1815,1817,1819,1821,1823,1825],{"class":1351,"line":76},[1349,1805,1748],{"class":1354},[1349,1807,1751],{"class":1716},[1349,1809,1726],{"class":1354},[1349,1811,1812],{"class":1369},"\"#saveButton\"",[1349,1814,1759],{"class":1354},[1349,1816,1762],{"class":1716},[1349,1818,1726],{"class":1354},[1349,1820,1767],{"class":1369},[1349,1822,1770],{"class":1354},[1349,1824,1773],{"class":1700},[1349,1826,1776],{"class":1354},[1349,1828,1829,1831,1834],{"class":1351,"line":247},[1349,1830,1781],{"class":1354},[1349,1832,1833],{"class":1716},"hide",[1349,1835,1787],{"class":1354},[1349,1837,1838],{"class":1351,"line":236},[1349,1839,1792],{"class":1354},[1349,1841,1842],{"class":1351,"line":225},[1349,1843,1737],{"emptyLinePlaceholder":1736},[1349,1845,1846],{"class":1351,"line":214},[1349,1847,1848],{"class":1742},"\u002F\u002F Modal 關閉按鈕\n",[1349,1850,1851,1853,1855,1857,1860,1862,1864,1866,1868,1870,1872],{"class":1351,"line":203},[1349,1852,1748],{"class":1354},[1349,1854,1751],{"class":1716},[1349,1856,1726],{"class":1354},[1349,1858,1859],{"class":1369},"\"#closeButton\"",[1349,1861,1759],{"class":1354},[1349,1863,1762],{"class":1716},[1349,1865,1726],{"class":1354},[1349,1867,1767],{"class":1369},[1349,1869,1770],{"class":1354},[1349,1871,1773],{"class":1700},[1349,1873,1776],{"class":1354},[1349,1875,1876,1878,1880],{"class":1351,"line":192},[1349,1877,1781],{"class":1354},[1349,1879,1833],{"class":1716},[1349,1881,1787],{"class":1354},[1349,1883,1884],{"class":1351,"line":181},[1349,1885,1792],{"class":1354},[1250,1887],{},[1216,1889,1890],{},"接著我們將上面的控制方式改成使用 Vue 進行管控。",[1216,1892,1328,1893],{},[1330,1894,1897],{"href":1895,"rel":1896},"https:\u002F\u002Fcodepen.io\u002Fgwhvusel-the-builder\u002Fpen\u002FeYwjzaw",[1334],"Vue3 Options API Bootstrap Modal ref 實作連結",[1307,1899,1900,1910],{},[1231,1901,1902,1903,1906,1907,1909],{},"原先透過",[1260,1904,1905],{},"document.getElementById(\"modal\")","的部分取得的 DOM 元素，改成透過",[1260,1908,1278],{},"的方式取得。",[1231,1911,1912,1913,1916,1917,1920,1921,1267,1923,1325],{},"監聽 Modal 內的儲存(Save)按鈕跟關閉(Close)按鈕，透過",[1260,1914,1915],{},"v-on","綁定",[1260,1918,1919],{},"click","事件，點擊的時候觸發對應的方法",[1260,1922,1321],{},[1260,1924,1324],{},[1216,1926,1927],{},"Vue Template：",[1340,1929,1931],{"className":1342,"code":1930,"language":1344,"meta":1345,"style":1345},"\u003Cdiv id=\"app\">\n  \u003Cdiv class=\"p-4\">\n    \u003Cbutton @click=\"openModal\" id=\"openModal\" type=\"button\" class=\"btn btn-primary\">打開 modal\u003C\u002Fbutton>\n    \u003Cdiv class=\"modal\" tabindex=\"-1\" role=\"dialog\" ref=\"modal\">\n      \u003Cdiv class=\"modal-dialog\" role=\"document\">\n        \u003Cdiv class=\"modal-content\">\n          \u003Cdiv class=\"modal-header\">\n            \u003Ch5 class=\"modal-title\">Modal title\u003C\u002Fh5>\n            \u003Cbutton type=\"button\" class=\"btn-close\" data-bs-dismiss=\"modal\" aria-label=\"Close\">\u003C\u002Fbutton>\n          \u003C\u002Fdiv>\n          \u003Cdiv class=\"modal-body\">\n            \u003Cp>Modal body text goes here.\u003C\u002Fp>\n          \u003C\u002Fdiv>\n          \u003Cdiv class=\"modal-footer\">\n            \u003Cbutton @click=\"closeModal\" id=\"saveButton\" type=\"button\" class=\"btn btn-primary\">Save changes\u003C\u002Fbutton>\n            \u003Cbutton @click=\"closeModal\" id=\"closeButton\" type=\"button\" class=\"btn btn-secondary\" data-dismiss=\"modal\">Close\u003C\u002Fbutton>\n          \u003C\u002Fdiv>\n        \u003C\u002Fdiv>\n      \u003C\u002Fdiv>\n    \u003C\u002Fdiv>\n  \u003C\u002Fdiv>\n\u003C\u002Fdiv>\n",[1260,1932,1933,1949,1964,2003,2036,2056,2070,2084,2103,2139,2148,2162,2174,2182,2196,2233,2275,2283,2291,2299,2307,2315],{"__ignoreMap":1345},[1349,1934,1935,1938,1940,1942,1944,1947],{"class":1351,"line":340},[1349,1936,1937],{"class":1354},"\u003C",[1349,1939,1359],{"class":1358},[1349,1941,1389],{"class":1362},[1349,1943,1366],{"class":1354},[1349,1945,1946],{"class":1369},"\"app\"",[1349,1948,1396],{"class":1354},[1349,1950,1951,1953,1955,1957,1959,1962],{"class":1351,"line":329},[1349,1952,1355],{"class":1354},[1349,1954,1359],{"class":1358},[1349,1956,1363],{"class":1362},[1349,1958,1366],{"class":1354},[1349,1960,1961],{"class":1369},"\"p-4\"",[1349,1963,1396],{"class":1354},[1349,1965,1966,1968,1970,1973,1975,1978,1980,1982,1984,1986,1988,1990,1992,1994,1996,1999,2001],{"class":1351,"line":318},[1349,1967,1401],{"class":1354},[1349,1969,1480],{"class":1358},[1349,1971,1972],{"class":1362}," @click",[1349,1974,1366],{"class":1354},[1349,1976,1977],{"class":1369},"\"openModal\"",[1349,1979,1389],{"class":1362},[1349,1981,1366],{"class":1354},[1349,1983,1977],{"class":1369},[1349,1985,1483],{"class":1362},[1349,1987,1366],{"class":1354},[1349,1989,1488],{"class":1369},[1349,1991,1363],{"class":1362},[1349,1993,1366],{"class":1354},[1349,1995,1603],{"class":1369},[1349,1997,1998],{"class":1354},">打開 modal\u003C\u002F",[1349,2000,1480],{"class":1358},[1349,2002,1396],{"class":1354},[1349,2004,2005,2007,2009,2011,2013,2015,2017,2019,2021,2023,2025,2027,2030,2032,2034],{"class":1351,"line":134},[1349,2006,1401],{"class":1354},[1349,2008,1359],{"class":1358},[1349,2010,1363],{"class":1362},[1349,2012,1366],{"class":1354},[1349,2014,1370],{"class":1369},[1349,2016,1373],{"class":1362},[1349,2018,1366],{"class":1354},[1349,2020,1378],{"class":1369},[1349,2022,1381],{"class":1362},[1349,2024,1366],{"class":1354},[1349,2026,1386],{"class":1369},[1349,2028,2029],{"class":1362}," ref",[1349,2031,1366],{"class":1354},[1349,2033,1370],{"class":1369},[1349,2035,1396],{"class":1354},[1349,2037,2038,2040,2042,2044,2046,2048,2050,2052,2054],{"class":1351,"line":122},[1349,2039,1424],{"class":1354},[1349,2041,1359],{"class":1358},[1349,2043,1363],{"class":1362},[1349,2045,1366],{"class":1354},[1349,2047,1410],{"class":1369},[1349,2049,1381],{"class":1362},[1349,2051,1366],{"class":1354},[1349,2053,1417],{"class":1369},[1349,2055,1396],{"class":1354},[1349,2057,2058,2060,2062,2064,2066,2068],{"class":1351,"line":31},[1349,2059,1440],{"class":1354},[1349,2061,1359],{"class":1358},[1349,2063,1363],{"class":1362},[1349,2065,1366],{"class":1354},[1349,2067,1433],{"class":1369},[1349,2069,1396],{"class":1354},[1349,2071,2072,2074,2076,2078,2080,2082],{"class":1351,"line":17},[1349,2073,1456],{"class":1354},[1349,2075,1359],{"class":1358},[1349,2077,1363],{"class":1362},[1349,2079,1366],{"class":1354},[1349,2081,1449],{"class":1369},[1349,2083,1396],{"class":1354},[1349,2085,2086,2089,2091,2093,2095,2097,2099,2101],{"class":1351,"line":110},[1349,2087,2088],{"class":1354},"            \u003C",[1349,2090,1459],{"class":1358},[1349,2092,1363],{"class":1362},[1349,2094,1366],{"class":1354},[1349,2096,1466],{"class":1369},[1349,2098,1469],{"class":1354},[1349,2100,1459],{"class":1358},[1349,2102,1396],{"class":1354},[1349,2104,2105,2107,2109,2111,2113,2115,2117,2119,2121,2123,2125,2127,2129,2131,2133,2135,2137],{"class":1351,"line":76},[1349,2106,2088],{"class":1354},[1349,2108,1480],{"class":1358},[1349,2110,1483],{"class":1362},[1349,2112,1366],{"class":1354},[1349,2114,1488],{"class":1369},[1349,2116,1363],{"class":1362},[1349,2118,1366],{"class":1354},[1349,2120,1495],{"class":1369},[1349,2122,1498],{"class":1362},[1349,2124,1366],{"class":1354},[1349,2126,1370],{"class":1369},[1349,2128,1505],{"class":1362},[1349,2130,1366],{"class":1354},[1349,2132,1510],{"class":1369},[1349,2134,1513],{"class":1354},[1349,2136,1480],{"class":1358},[1349,2138,1396],{"class":1354},[1349,2140,2141,2144,2146],{"class":1351,"line":247},[1349,2142,2143],{"class":1354},"          \u003C\u002F",[1349,2145,1359],{"class":1358},[1349,2147,1396],{"class":1354},[1349,2149,2150,2152,2154,2156,2158,2160],{"class":1351,"line":236},[1349,2151,1456],{"class":1354},[1349,2153,1359],{"class":1358},[1349,2155,1363],{"class":1362},[1349,2157,1366],{"class":1354},[1349,2159,1539],{"class":1369},[1349,2161,1396],{"class":1354},[1349,2163,2164,2166,2168,2170,2172],{"class":1351,"line":225},[1349,2165,2088],{"class":1354},[1349,2167,1216],{"class":1358},[1349,2169,1550],{"class":1354},[1349,2171,1216],{"class":1358},[1349,2173,1396],{"class":1354},[1349,2175,2176,2178,2180],{"class":1351,"line":214},[1349,2177,2143],{"class":1354},[1349,2179,1359],{"class":1358},[1349,2181,1396],{"class":1354},[1349,2183,2184,2186,2188,2190,2192,2194],{"class":1351,"line":203},[1349,2185,1456],{"class":1354},[1349,2187,1359],{"class":1358},[1349,2189,1363],{"class":1362},[1349,2191,1366],{"class":1354},[1349,2193,1575],{"class":1369},[1349,2195,1396],{"class":1354},[1349,2197,2198,2200,2202,2204,2206,2209,2211,2213,2215,2217,2219,2221,2223,2225,2227,2229,2231],{"class":1351,"line":192},[1349,2199,2088],{"class":1354},[1349,2201,1480],{"class":1358},[1349,2203,1972],{"class":1362},[1349,2205,1366],{"class":1354},[1349,2207,2208],{"class":1369},"\"closeModal\"",[1349,2210,1389],{"class":1362},[1349,2212,1366],{"class":1354},[1349,2214,1590],{"class":1369},[1349,2216,1483],{"class":1362},[1349,2218,1366],{"class":1354},[1349,2220,1488],{"class":1369},[1349,2222,1363],{"class":1362},[1349,2224,1366],{"class":1354},[1349,2226,1603],{"class":1369},[1349,2228,1606],{"class":1354},[1349,2230,1480],{"class":1358},[1349,2232,1396],{"class":1354},[1349,2234,2235,2237,2239,2241,2243,2245,2247,2249,2251,2253,2255,2257,2259,2261,2263,2265,2267,2269,2271,2273],{"class":1351,"line":181},[1349,2236,2088],{"class":1354},[1349,2238,1480],{"class":1358},[1349,2240,1972],{"class":1362},[1349,2242,1366],{"class":1354},[1349,2244,2208],{"class":1369},[1349,2246,1389],{"class":1362},[1349,2248,1366],{"class":1354},[1349,2250,1623],{"class":1369},[1349,2252,1483],{"class":1362},[1349,2254,1366],{"class":1354},[1349,2256,1488],{"class":1369},[1349,2258,1363],{"class":1362},[1349,2260,1366],{"class":1354},[1349,2262,1636],{"class":1369},[1349,2264,1639],{"class":1362},[1349,2266,1366],{"class":1354},[1349,2268,1370],{"class":1369},[1349,2270,1646],{"class":1354},[1349,2272,1480],{"class":1358},[1349,2274,1396],{"class":1354},[1349,2276,2277,2279,2281],{"class":1351,"line":170},[1349,2278,2143],{"class":1354},[1349,2280,1359],{"class":1358},[1349,2282,1396],{"class":1354},[1349,2284,2285,2287,2289],{"class":1351,"line":159},[1349,2286,1522],{"class":1354},[1349,2288,1359],{"class":1358},[1349,2290,1396],{"class":1354},[1349,2292,2293,2295,2297],{"class":1351,"line":148},[1349,2294,1663],{"class":1354},[1349,2296,1359],{"class":1358},[1349,2298,1396],{"class":1354},[1349,2300,2301,2303,2305],{"class":1351,"line":137},[1349,2302,1672],{"class":1354},[1349,2304,1359],{"class":1358},[1349,2306,1396],{"class":1354},[1349,2308,2309,2311,2313],{"class":1351,"line":125},[1349,2310,1681],{"class":1354},[1349,2312,1359],{"class":1358},[1349,2314,1396],{"class":1354},[1349,2316,2317,2320,2322],{"class":1351,"line":113},[1349,2318,2319],{"class":1354},"\u003C\u002F",[1349,2321,1359],{"class":1358},[1349,2323,1396],{"class":1354},[1216,2325,1688],{},[1340,2327,2329],{"className":1691,"code":2328,"language":1693,"meta":1345,"style":1345},"const rootComponent = {\n  data() {\n    return {\n      myModal: null\n    };\n  },\n  methods: {\n    \u002F\u002F 開啟 Modal\n    openModal() {\n      this.myModal.show();\n    },\n    \u002F\u002F 關閉 Modal\n    closeModal() {\n      this.myModal.hide();\n    }\n  },\n  mounted() {\n    this.myModal = new bootstrap.Modal(this.$refs.modal);\n  }\n};\n",[1260,2330,2331,2343,2351,2358,2366,2371,2376,2381,2386,2393,2405,2410,2415,2422,2432,2437,2441,2448,2471,2476],{"__ignoreMap":1345},[1349,2332,2333,2335,2338,2340],{"class":1351,"line":340},[1349,2334,1029],{"class":1700},[1349,2336,2337],{"class":1703}," rootComponent",[1349,2339,1707],{"class":1700},[1349,2341,2342],{"class":1354}," {\n",[1349,2344,2345,2348],{"class":1351,"line":329},[1349,2346,2347],{"class":1716},"  data",[1349,2349,2350],{"class":1354},"() {\n",[1349,2352,2353,2356],{"class":1351,"line":318},[1349,2354,2355],{"class":1700},"    return",[1349,2357,2342],{"class":1354},[1349,2359,2360,2363],{"class":1351,"line":134},[1349,2361,2362],{"class":1354},"      myModal: ",[1349,2364,2365],{"class":1703},"null\n",[1349,2367,2368],{"class":1351,"line":122},[1349,2369,2370],{"class":1354},"    };\n",[1349,2372,2373],{"class":1351,"line":31},[1349,2374,2375],{"class":1354},"  },\n",[1349,2377,2378],{"class":1351,"line":17},[1349,2379,2380],{"class":1354},"  methods: {\n",[1349,2382,2383],{"class":1351,"line":110},[1349,2384,2385],{"class":1742},"    \u002F\u002F 開啟 Modal\n",[1349,2387,2388,2391],{"class":1351,"line":76},[1349,2389,2390],{"class":1716},"    openModal",[1349,2392,2350],{"class":1354},[1349,2394,2395,2398,2401,2403],{"class":1351,"line":247},[1349,2396,2397],{"class":1703},"      this",[1349,2399,2400],{"class":1354},".myModal.",[1349,2402,1784],{"class":1716},[1349,2404,1787],{"class":1354},[1349,2406,2407],{"class":1351,"line":236},[1349,2408,2409],{"class":1354},"    },\n",[1349,2411,2412],{"class":1351,"line":225},[1349,2413,2414],{"class":1742},"    \u002F\u002F 關閉 Modal\n",[1349,2416,2417,2420],{"class":1351,"line":214},[1349,2418,2419],{"class":1716},"    closeModal",[1349,2421,2350],{"class":1354},[1349,2423,2424,2426,2428,2430],{"class":1351,"line":203},[1349,2425,2397],{"class":1703},[1349,2427,2400],{"class":1354},[1349,2429,1833],{"class":1716},[1349,2431,1787],{"class":1354},[1349,2433,2434],{"class":1351,"line":192},[1349,2435,2436],{"class":1354},"    }\n",[1349,2438,2439],{"class":1351,"line":181},[1349,2440,2375],{"class":1354},[1349,2442,2443,2446],{"class":1351,"line":170},[1349,2444,2445],{"class":1716},"  mounted",[1349,2447,2350],{"class":1354},[1349,2449,2450,2453,2456,2458,2460,2462,2464,2466,2468],{"class":1351,"line":159},[1349,2451,2452],{"class":1703},"    this",[1349,2454,2455],{"class":1354},".myModal ",[1349,2457,1366],{"class":1700},[1349,2459,1710],{"class":1700},[1349,2461,1713],{"class":1354},[1349,2463,1717],{"class":1716},[1349,2465,1726],{"class":1354},[1349,2467,1128],{"class":1703},[1349,2469,2470],{"class":1354},".$refs.modal);\n",[1349,2472,2473],{"class":1351,"line":148},[1349,2474,2475],{"class":1354},"  }\n",[1349,2477,2478],{"class":1351,"line":137},[1349,2479,2480],{"class":1354},"};\n",[1216,2482,2483,2484,2486,2487,2490,2491,2494],{},"⭐ 預設",[1260,2485,1278],{},"對象會是",[1260,2488,2489],{},"undefined","如果需要讀取到其對應的DOM 元素需要在",[1260,2492,2493],{},"mouted","模板渲染完成之後的階段。",[1253,2496,2498],{"id":2497},"ref-搭配-video-web-api-使用","ref 搭配 Video Web API 使用",[1216,2500,2501,2502,2505,2506,1267,2509,2512,2513,2515],{},"除了上述與第三方套件搭配的案例外，在使用像",[1260,2503,2504],{},"video","這類的原生 HTML 標籤時，也經常需要使用其內建的 Web API，例如：",[1260,2507,2508],{},"play()",[1260,2510,2511],{},"pause()","方法來控制播放行為。在這些情況下，可以利用 Vue 的",[1260,2514,1278],{},"屬性來標記這些 DOM 元素，以便進行手動控制和操作。",[1216,2517,1328,2518],{},[1330,2519,2522],{"href":2520,"rel":2521},"https:\u002F\u002Fcodepen.io\u002Fgwhvusel-the-builder\u002Fpen\u002FyLdqajy",[1334],"Vue3 Options API HTML video tag with ref 實作連結",[1216,2524,1927],{},[1340,2526,2528],{"className":1342,"code":2527,"language":1344,"meta":1345,"style":1345},"\u003Cvideo src=\"https:\u002F\u002Fwww.w3schools.com\u002Fhtml\u002Fmov_bbb.mp4\" ref='video'>\u003C\u002Fvideo>\n\u003Cdiv class=\"btn-group\" role=\"group\" aria-label=\"Basic example\">\n  \u003Cbutton @click=\"play\" type=\"button\" class=\"btn btn-secondary\">play\u003C\u002Fbutton>\n  \u003Cbutton @click=\"pause\" type=\"button\" class=\"btn btn-secondary\">pause\u003C\u002Fbutton>\n  \u003Cbutton @click=\"reset\" type=\"button\" class=\"btn btn-secondary\">reset\u003C\u002Fbutton>\n",[1260,2529,2530,2557,2586,2618,2650],{"__ignoreMap":1345},[1349,2531,2532,2534,2536,2539,2541,2544,2546,2548,2551,2553,2555],{"class":1351,"line":340},[1349,2533,1937],{"class":1354},[1349,2535,2504],{"class":1358},[1349,2537,2538],{"class":1362}," src",[1349,2540,1366],{"class":1354},[1349,2542,2543],{"class":1369},"\"https:\u002F\u002Fwww.w3schools.com\u002Fhtml\u002Fmov_bbb.mp4\"",[1349,2545,2029],{"class":1362},[1349,2547,1366],{"class":1354},[1349,2549,2550],{"class":1369},"'video'",[1349,2552,1513],{"class":1354},[1349,2554,2504],{"class":1358},[1349,2556,1396],{"class":1354},[1349,2558,2559,2561,2563,2565,2567,2570,2572,2574,2577,2579,2581,2584],{"class":1351,"line":329},[1349,2560,1937],{"class":1354},[1349,2562,1359],{"class":1358},[1349,2564,1363],{"class":1362},[1349,2566,1366],{"class":1354},[1349,2568,2569],{"class":1369},"\"btn-group\"",[1349,2571,1381],{"class":1362},[1349,2573,1366],{"class":1354},[1349,2575,2576],{"class":1369},"\"group\"",[1349,2578,1505],{"class":1362},[1349,2580,1366],{"class":1354},[1349,2582,2583],{"class":1369},"\"Basic example\"",[1349,2585,1396],{"class":1354},[1349,2587,2588,2590,2592,2594,2596,2599,2601,2603,2605,2607,2609,2611,2614,2616],{"class":1351,"line":318},[1349,2589,1355],{"class":1354},[1349,2591,1480],{"class":1358},[1349,2593,1972],{"class":1362},[1349,2595,1366],{"class":1354},[1349,2597,2598],{"class":1369},"\"play\"",[1349,2600,1483],{"class":1362},[1349,2602,1366],{"class":1354},[1349,2604,1488],{"class":1369},[1349,2606,1363],{"class":1362},[1349,2608,1366],{"class":1354},[1349,2610,1636],{"class":1369},[1349,2612,2613],{"class":1354},">play\u003C\u002F",[1349,2615,1480],{"class":1358},[1349,2617,1396],{"class":1354},[1349,2619,2620,2622,2624,2626,2628,2631,2633,2635,2637,2639,2641,2643,2646,2648],{"class":1351,"line":134},[1349,2621,1355],{"class":1354},[1349,2623,1480],{"class":1358},[1349,2625,1972],{"class":1362},[1349,2627,1366],{"class":1354},[1349,2629,2630],{"class":1369},"\"pause\"",[1349,2632,1483],{"class":1362},[1349,2634,1366],{"class":1354},[1349,2636,1488],{"class":1369},[1349,2638,1363],{"class":1362},[1349,2640,1366],{"class":1354},[1349,2642,1636],{"class":1369},[1349,2644,2645],{"class":1354},">pause\u003C\u002F",[1349,2647,1480],{"class":1358},[1349,2649,1396],{"class":1354},[1349,2651,2652,2654,2656,2658,2660,2663,2665,2667,2669,2671,2673,2675,2678,2680],{"class":1351,"line":122},[1349,2653,1355],{"class":1354},[1349,2655,1480],{"class":1358},[1349,2657,1972],{"class":1362},[1349,2659,1366],{"class":1354},[1349,2661,2662],{"class":1369},"\"reset\"",[1349,2664,1483],{"class":1362},[1349,2666,1366],{"class":1354},[1349,2668,1488],{"class":1369},[1349,2670,1363],{"class":1362},[1349,2672,1366],{"class":1354},[1349,2674,1636],{"class":1369},[1349,2676,2677],{"class":1354},">reset\u003C\u002F",[1349,2679,1480],{"class":1358},[1349,2681,1396],{"class":1354},[1216,2683,1688],{},[1340,2685,2687],{"className":1691,"code":2686,"language":1693,"meta":1345,"style":1345},"const rootComponent = {\n  data() {\n    return {\n      videoInstance: null\n    };\n  },\n  methods: {\n    play() {\n      this.videoInstance.play();\n    },\n    pause() {\n      this.videoInstance.pause();\n    },\n    reset() {\n      this.videoInstance.pause();\n      this.videoInstance.currentTime = 0;\n    }\n  },\n  mounted() {\n    this.videoInstance = this.$refs.video;\n  }\n};\n",[1260,2688,2689,2699,2705,2711,2718,2722,2726,2730,2737,2749,2753,2760,2771,2775,2782,2792,2807,2811,2815,2821,2836,2840],{"__ignoreMap":1345},[1349,2690,2691,2693,2695,2697],{"class":1351,"line":340},[1349,2692,1029],{"class":1700},[1349,2694,2337],{"class":1703},[1349,2696,1707],{"class":1700},[1349,2698,2342],{"class":1354},[1349,2700,2701,2703],{"class":1351,"line":329},[1349,2702,2347],{"class":1716},[1349,2704,2350],{"class":1354},[1349,2706,2707,2709],{"class":1351,"line":318},[1349,2708,2355],{"class":1700},[1349,2710,2342],{"class":1354},[1349,2712,2713,2716],{"class":1351,"line":134},[1349,2714,2715],{"class":1354},"      videoInstance: ",[1349,2717,2365],{"class":1703},[1349,2719,2720],{"class":1351,"line":122},[1349,2721,2370],{"class":1354},[1349,2723,2724],{"class":1351,"line":31},[1349,2725,2375],{"class":1354},[1349,2727,2728],{"class":1351,"line":17},[1349,2729,2380],{"class":1354},[1349,2731,2732,2735],{"class":1351,"line":110},[1349,2733,2734],{"class":1716},"    play",[1349,2736,2350],{"class":1354},[1349,2738,2739,2741,2744,2747],{"class":1351,"line":76},[1349,2740,2397],{"class":1703},[1349,2742,2743],{"class":1354},".videoInstance.",[1349,2745,2746],{"class":1716},"play",[1349,2748,1787],{"class":1354},[1349,2750,2751],{"class":1351,"line":247},[1349,2752,2409],{"class":1354},[1349,2754,2755,2758],{"class":1351,"line":236},[1349,2756,2757],{"class":1716},"    pause",[1349,2759,2350],{"class":1354},[1349,2761,2762,2764,2766,2769],{"class":1351,"line":225},[1349,2763,2397],{"class":1703},[1349,2765,2743],{"class":1354},[1349,2767,2768],{"class":1716},"pause",[1349,2770,1787],{"class":1354},[1349,2772,2773],{"class":1351,"line":214},[1349,2774,2409],{"class":1354},[1349,2776,2777,2780],{"class":1351,"line":203},[1349,2778,2779],{"class":1716},"    reset",[1349,2781,2350],{"class":1354},[1349,2783,2784,2786,2788,2790],{"class":1351,"line":192},[1349,2785,2397],{"class":1703},[1349,2787,2743],{"class":1354},[1349,2789,2768],{"class":1716},[1349,2791,1787],{"class":1354},[1349,2793,2794,2796,2799,2801,2804],{"class":1351,"line":181},[1349,2795,2397],{"class":1703},[1349,2797,2798],{"class":1354},".videoInstance.currentTime ",[1349,2800,1366],{"class":1700},[1349,2802,2803],{"class":1703}," 0",[1349,2805,2806],{"class":1354},";\n",[1349,2808,2809],{"class":1351,"line":170},[1349,2810,2436],{"class":1354},[1349,2812,2813],{"class":1351,"line":159},[1349,2814,2375],{"class":1354},[1349,2816,2817,2819],{"class":1351,"line":148},[1349,2818,2445],{"class":1716},[1349,2820,2350],{"class":1354},[1349,2822,2823,2825,2828,2830,2833],{"class":1351,"line":137},[1349,2824,2452],{"class":1703},[1349,2826,2827],{"class":1354},".videoInstance ",[1349,2829,1366],{"class":1700},[1349,2831,2832],{"class":1703}," this",[1349,2834,2835],{"class":1354},".$refs.video;\n",[1349,2837,2838],{"class":1351,"line":125},[1349,2839,2475],{"class":1354},[1349,2841,2842],{"class":1351,"line":113},[1349,2843,2480],{"class":1354},[1253,2845,1239],{"id":2846},"v-for-搭配陣列儲存-ref-屬性使用",[1216,2848,2849,2850,2852,2853,2856,2857,2860,2861,2864],{},"在 Vue 中，當",[1260,2851,1278],{},"與",[1260,2854,2855],{},"v-for 指令","一起使用時，Vue 會自動將生成的 DOM 元素存儲在一個",[1260,2858,2859],{},"陣列","中。可以透過",[1260,2862,2863],{},"this.$refs","訪問這些元素。",[1216,2866,1328,2867],{},[1330,2868,2871],{"href":2869,"rel":2870},"https:\u002F\u002Fcodepen.io\u002Fgwhvusel-the-builder\u002Fpen\u002FLYKBbmX",[1334],"Vue3 Options API v-for 搭配 ref 陣列實作連結",[1216,2873,1927],{},[1340,2875,2877],{"className":1342,"code":2876,"language":1344,"meta":1345,"style":1345},"\u003Cul>\n  \u003Cli v-for=\"item in productList\" :key=\"item\" ref=\"items\">{{ item }}\u003C\u002Fli>\n\u003C\u002Ful>\n",[1260,2878,2879,2887,2923],{"__ignoreMap":1345},[1349,2880,2881,2883,2885],{"class":1351,"line":340},[1349,2882,1937],{"class":1354},[1349,2884,1228],{"class":1358},[1349,2886,1396],{"class":1354},[1349,2888,2889,2891,2893,2896,2898,2901,2904,2906,2909,2911,2913,2916,2919,2921],{"class":1351,"line":329},[1349,2890,1355],{"class":1354},[1349,2892,1231],{"class":1358},[1349,2894,2895],{"class":1362}," v-for",[1349,2897,1366],{"class":1354},[1349,2899,2900],{"class":1369},"\"item in productList\"",[1349,2902,2903],{"class":1362}," :key",[1349,2905,1366],{"class":1354},[1349,2907,2908],{"class":1369},"\"item\"",[1349,2910,2029],{"class":1362},[1349,2912,1366],{"class":1354},[1349,2914,2915],{"class":1369},"\"items\"",[1349,2917,2918],{"class":1354},">{{ item }}\u003C\u002F",[1349,2920,1231],{"class":1358},[1349,2922,1396],{"class":1354},[1349,2924,2925,2927,2929],{"class":1351,"line":318},[1349,2926,2319],{"class":1354},[1349,2928,1228],{"class":1358},[1349,2930,1396],{"class":1354},[1216,2932,1688],{},[1340,2934,2936],{"className":1691,"code":2935,"language":1693,"meta":1345,"style":1345},"const app = createApp({\n  data() {\n    return {\n      productList: [\"Apple\", \"Orange\", \"Banana\"]\n    };\n  }\n  mounted() {\n    console.log(\"this.items\", this.$refs.items);\n  }\n});\n",[1260,2937,2938,2953,2959,2965,2986,2990,2994,3000,3020,3024],{"__ignoreMap":1345},[1349,2939,2940,2942,2945,2947,2950],{"class":1351,"line":340},[1349,2941,1029],{"class":1700},[1349,2943,2944],{"class":1703}," app",[1349,2946,1707],{"class":1700},[1349,2948,2949],{"class":1716}," createApp",[1349,2951,2952],{"class":1354},"({\n",[1349,2954,2955,2957],{"class":1351,"line":329},[1349,2956,2347],{"class":1716},[1349,2958,2350],{"class":1354},[1349,2960,2961,2963],{"class":1351,"line":318},[1349,2962,2355],{"class":1700},[1349,2964,2342],{"class":1354},[1349,2966,2967,2970,2973,2975,2978,2980,2983],{"class":1351,"line":134},[1349,2968,2969],{"class":1354},"      productList: [",[1349,2971,2972],{"class":1369},"\"Apple\"",[1349,2974,1770],{"class":1354},[1349,2976,2977],{"class":1369},"\"Orange\"",[1349,2979,1770],{"class":1354},[1349,2981,2982],{"class":1369},"\"Banana\"",[1349,2984,2985],{"class":1354},"]\n",[1349,2987,2988],{"class":1351,"line":122},[1349,2989,2370],{"class":1354},[1349,2991,2992],{"class":1351,"line":31},[1349,2993,2475],{"class":1354},[1349,2995,2996,2998],{"class":1351,"line":17},[1349,2997,2445],{"class":1716},[1349,2999,2350],{"class":1354},[1349,3001,3002,3005,3008,3010,3013,3015,3017],{"class":1351,"line":110},[1349,3003,3004],{"class":1354},"    console.",[1349,3006,3007],{"class":1716},"log",[1349,3009,1726],{"class":1354},[1349,3011,3012],{"class":1369},"\"this.items\"",[1349,3014,1770],{"class":1354},[1349,3016,1128],{"class":1703},[1349,3018,3019],{"class":1354},".$refs.items);\n",[1349,3021,3022],{"class":1351,"line":76},[1349,3023,2475],{"class":1354},[1349,3025,3026],{"class":1351,"line":247},[1349,3027,1792],{"class":1354},[1216,3029,3030,3031,3034],{},"⭐ 無法保證綁定陣列中",[1260,3032,3033],{},"ref 屬性","的順序與原始陣列數據的順序一致",[1253,3036,1242],{"id":3037},"動態-ref-屬性綁定方法",[1216,3039,3040,3041,3044,3045,3047,3048,3051],{},"可以透過綁定一個",[1260,3042,3043],{},"動態 ref 屬性","，在每次模板更新時將該",[1260,3046,1278],{},"傳入到一個函數中進行處理。如果綁定的元素被銷毀，傳入函數的參數值將會自動變為",[1260,3049,3050],{},"null","。",[1216,3053,3054],{},"流程說明：",[1307,3056,3057,3060],{},[1231,3058,3059],{},"透過按【切換顯示使用者帳號輸入框】按鈕切換使用者帳號輸入欄位的顯示與隱藏。",[1231,3061,3062,3063,3066],{},"當使用者帳號輸入欄位出現時，透過",[1260,3064,3065],{},"動態綁定的 ref 屬性","，自動將焦點聚焦到該輸入框，達到 focus() 效果。",[1216,3068,1328,3069],{},[1330,3070,3073],{"href":3071,"rel":3072},"https:\u002F\u002Fcodepen.io\u002Fgwhvusel-the-builder\u002Fpen\u002FKKjBZeO",[1334],"Vue3 Options API ref 動態綁定方法(method)實作連結",[1216,3075,3076],{},[1219,3077],{"alt":3078,"src":3079},"動態綁定 ref 屬性取得元素焦點","https:\u002F\u002Fres.cloudinary.com\u002Fdseg0uwc9\u002Fimage\u002Fupload\u002Fv1727596419\u002F2024%20%E9%90%B5%E4%BA%BA%E8%B3%BD\u002FDay%2016%EF%BC%9A%E6%A8%A1%E6%9D%BF%E5%BC%95%E7%94%A8%28ref%29\u002F%E5%8B%95%E6%85%8B%E7%B6%81%E5%AE%9A_ref_%E5%B1%AC%E6%80%A7%E5%8F%96%E5%BE%97%E5%85%83%E7%B4%A0%E7%84%A6%E9%BB%9E_qtlk2t.png",[1216,3081,1927],{},[1340,3083,3085],{"className":1342,"code":3084,"language":1344,"meta":1345,"style":1345},"\u003Cdiv v-if=\"isShowAccount\" class=\"input-group\">\n  \u003Clabel for=\"inputAccount\">使用者帳號：\u003C\u002Flabel>\n  \u003Cinput id=\"inputAccount\" type=\"text\" :ref=\"setRef\">\n\u003C\u002Fdiv>\n\u003Cbutton @click=\"register\" type=\"button\">切換顯示使用者帳號輸入框\u003C\u002Fbutton>\n",[1260,3086,3087,3110,3132,3162,3170],{"__ignoreMap":1345},[1349,3088,3089,3091,3093,3096,3098,3101,3103,3105,3108],{"class":1351,"line":340},[1349,3090,1937],{"class":1354},[1349,3092,1359],{"class":1358},[1349,3094,3095],{"class":1362}," v-if",[1349,3097,1366],{"class":1354},[1349,3099,3100],{"class":1369},"\"isShowAccount\"",[1349,3102,1363],{"class":1362},[1349,3104,1366],{"class":1354},[1349,3106,3107],{"class":1369},"\"input-group\"",[1349,3109,1396],{"class":1354},[1349,3111,3112,3114,3117,3120,3122,3125,3128,3130],{"class":1351,"line":329},[1349,3113,1355],{"class":1354},[1349,3115,3116],{"class":1358},"label",[1349,3118,3119],{"class":1362}," for",[1349,3121,1366],{"class":1354},[1349,3123,3124],{"class":1369},"\"inputAccount\"",[1349,3126,3127],{"class":1354},">使用者帳號：\u003C\u002F",[1349,3129,3116],{"class":1358},[1349,3131,1396],{"class":1354},[1349,3133,3134,3136,3139,3141,3143,3145,3147,3149,3152,3155,3157,3160],{"class":1351,"line":318},[1349,3135,1355],{"class":1354},[1349,3137,3138],{"class":1358},"input",[1349,3140,1389],{"class":1362},[1349,3142,1366],{"class":1354},[1349,3144,3124],{"class":1369},[1349,3146,1483],{"class":1362},[1349,3148,1366],{"class":1354},[1349,3150,3151],{"class":1369},"\"text\"",[1349,3153,3154],{"class":1362}," :ref",[1349,3156,1366],{"class":1354},[1349,3158,3159],{"class":1369},"\"setRef\"",[1349,3161,1396],{"class":1354},[1349,3163,3164,3166,3168],{"class":1351,"line":134},[1349,3165,2319],{"class":1354},[1349,3167,1359],{"class":1358},[1349,3169,1396],{"class":1354},[1349,3171,3172,3174,3176,3178,3180,3183,3185,3187,3189,3192,3194],{"class":1351,"line":122},[1349,3173,1937],{"class":1354},[1349,3175,1480],{"class":1358},[1349,3177,1972],{"class":1362},[1349,3179,1366],{"class":1354},[1349,3181,3182],{"class":1369},"\"register\"",[1349,3184,1483],{"class":1362},[1349,3186,1366],{"class":1354},[1349,3188,1488],{"class":1369},[1349,3190,3191],{"class":1354},">切換顯示使用者帳號輸入框\u003C\u002F",[1349,3193,1480],{"class":1358},[1349,3195,1396],{"class":1354},[1216,3197,1688],{},[1340,3199,3201],{"className":1691,"code":3200,"language":1693,"meta":1345,"style":1345},"  methods: {\n    setRef(ref) {\n      \u002F\u002F ref 是動態傳入的屬性\n      if (ref) {\n        this.$nextTick(() => {\n          ref.focus();\n        });\n      }\n    },\n    register() {\n      this.isShowAccount = !this.isShowAccount;\n    }\n  }\n...略\n",[1260,3202,3203,3212,3220,3225,3233,3252,3262,3267,3272,3276,3283,3300,3304,3308],{"__ignoreMap":1345},[1349,3204,3205,3209],{"class":1351,"line":340},[1349,3206,3208],{"class":3207},"sOLd2","  methods",[1349,3210,3211],{"class":1354},": {\n",[1349,3213,3214,3217],{"class":1351,"line":329},[1349,3215,3216],{"class":1716},"    setRef",[1349,3218,3219],{"class":1354},"(ref) {\n",[1349,3221,3222],{"class":1351,"line":318},[1349,3223,3224],{"class":1742},"      \u002F\u002F ref 是動態傳入的屬性\n",[1349,3226,3227,3230],{"class":1351,"line":134},[1349,3228,3229],{"class":1700},"      if",[1349,3231,3232],{"class":1354}," (ref) {\n",[1349,3234,3235,3238,3241,3244,3247,3250],{"class":1351,"line":122},[1349,3236,3237],{"class":1703},"        this",[1349,3239,3240],{"class":1354},".",[1349,3242,3243],{"class":1716},"$nextTick",[1349,3245,3246],{"class":1354},"(() ",[1349,3248,3249],{"class":1700},"=>",[1349,3251,2342],{"class":1354},[1349,3253,3254,3257,3260],{"class":1351,"line":31},[1349,3255,3256],{"class":1354},"          ref.",[1349,3258,3259],{"class":1716},"focus",[1349,3261,1787],{"class":1354},[1349,3263,3264],{"class":1351,"line":17},[1349,3265,3266],{"class":1354},"        });\n",[1349,3268,3269],{"class":1351,"line":110},[1349,3270,3271],{"class":1354},"      }\n",[1349,3273,3274],{"class":1351,"line":76},[1349,3275,2409],{"class":1354},[1349,3277,3278,3281],{"class":1351,"line":247},[1349,3279,3280],{"class":1716},"    register",[1349,3282,2350],{"class":1354},[1349,3284,3285,3287,3290,3292,3295,3297],{"class":1351,"line":236},[1349,3286,2397],{"class":1703},[1349,3288,3289],{"class":1354},".isShowAccount ",[1349,3291,1366],{"class":1700},[1349,3293,3294],{"class":1700}," !",[1349,3296,1128],{"class":1703},[1349,3298,3299],{"class":1354},".isShowAccount;\n",[1349,3301,3302],{"class":1351,"line":225},[1349,3303,2436],{"class":1354},[1349,3305,3306],{"class":1351,"line":214},[1349,3307,2475],{"class":1354},[1349,3309,3310,3313],{"class":1351,"line":203},[1349,3311,3312],{"class":1700},"...",[1349,3314,3315],{"class":1354},"略\n",[1253,3317,1245],{"id":3318},"組件實例搭配-ref-使用",[1216,3320,3321,3322,3324,3325,3328,3329,3331,3332,3334,3335,3338,3339,3341,3342,3344],{},"當",[1260,3323,3033],{},"被應用在 HTML 元素上時，它會標記並引用實際的",[1260,3326,3327],{},"HTML DOM 元素","；而當",[1260,3330,3033],{},"被應用在子組件上時，",[1260,3333,3033],{},"則會引用該",[1260,3336,3337],{},"子組件的實例","。透過這個",[1260,3340,3033],{},"，可以直接訪問子組件的內部數據和方法。不過，過度使用",[1260,3343,3033],{},"來操作子組件的資料和行為，可能會導致資料流混亂，需要謹慎使用。",[1216,3346,3054],{},[1307,3348,3349,3352],{},[1231,3350,3351],{},"子組件定義了一個計數器，使用變數 childCount 來記錄當前的計數值，並提供 addNum 方法來增加 childCount 的值，每次增加 1。",[1231,3353,3354],{},"在根組件中，透過 ref 屬性標記子組件的實例，並定義 getChildCount 方法來獲取子組件當前的 childCount 值，以及 addNum 方法來觸發子組件內部的 addNum 方法。",[1216,3356,3357],{},[1219,3358],{"alt":3359,"src":3360},"父組件透過 ref 屬性讀取子組件屬性及使用其方法","https:\u002F\u002Fres.cloudinary.com\u002Fdseg0uwc9\u002Fimage\u002Fupload\u002Fv1727661063\u002F2024%20%E9%90%B5%E4%BA%BA%E8%B3%BD\u002FDay%2016%EF%BC%9A%E6%A8%A1%E6%9D%BF%E5%BC%95%E7%94%A8%28ref%29\u002F%E7%88%B6%E7%B5%84%E4%BB%B6%E9%80%8F%E9%81%8E_ref_%E4%BD%BF%E7%94%A8%E5%AD%90%E7%B5%84%E4%BB%B6%E6%96%B9%E6%B3%95%E5%8F%8A%E5%8F%96%E5%BE%97%E5%AF%A6%E4%BE%8B%E8%AE%8A%E6%95%B8%E5%80%BC_jiifwa.png",[1216,3362,1328,3363],{},[1330,3364,3367],{"href":3365,"rel":3366},"https:\u002F\u002Fcodepen.io\u002Fgwhvusel-the-builder\u002Fpen\u002FxxoJYLW",[1334],"Vue3 Options API ref 取得組件實體內數據及方法實作連結",[1216,3369,3370],{},"父組件 Vue Template：",[1340,3372,3374],{"className":1342,"code":3373,"language":1344,"meta":1345,"style":1345},"\u003Cchild-component ref=\"child\">\u003C\u002Fchild-component>\n\u003Cp>取得子組件的響應式變數值：{{ RootCount }}\u003C\u002Fp>\n\u003Cbutton @click=\"getChildCount\" type=\"button\">取得子組件的響應試變數值\u003C\u002Fbutton>\n\u003Cbutton @click=\"addNum\" type=\"button\">使用子組件 addNum 增加子組件 childCount 變數值\u003C\u002Fbutton>\n",[1260,3375,3376,3396,3409,3435],{"__ignoreMap":1345},[1349,3377,3378,3380,3383,3385,3387,3390,3392,3394],{"class":1351,"line":340},[1349,3379,1937],{"class":1354},[1349,3381,3382],{"class":1358},"child-component",[1349,3384,2029],{"class":1362},[1349,3386,1366],{"class":1354},[1349,3388,3389],{"class":1369},"\"child\"",[1349,3391,1513],{"class":1354},[1349,3393,3382],{"class":1358},[1349,3395,1396],{"class":1354},[1349,3397,3398,3400,3402,3405,3407],{"class":1351,"line":329},[1349,3399,1937],{"class":1354},[1349,3401,1216],{"class":1358},[1349,3403,3404],{"class":1354},">取得子組件的響應式變數值：{{ RootCount }}\u003C\u002F",[1349,3406,1216],{"class":1358},[1349,3408,1396],{"class":1354},[1349,3410,3411,3413,3415,3417,3419,3422,3424,3426,3428,3431,3433],{"class":1351,"line":318},[1349,3412,1937],{"class":1354},[1349,3414,1480],{"class":1358},[1349,3416,1972],{"class":1362},[1349,3418,1366],{"class":1354},[1349,3420,3421],{"class":1369},"\"getChildCount\"",[1349,3423,1483],{"class":1362},[1349,3425,1366],{"class":1354},[1349,3427,1488],{"class":1369},[1349,3429,3430],{"class":1354},">取得子組件的響應試變數值\u003C\u002F",[1349,3432,1480],{"class":1358},[1349,3434,1396],{"class":1354},[1349,3436,3437,3439,3441,3443,3445,3448,3450,3452,3454,3457,3459],{"class":1351,"line":134},[1349,3438,1937],{"class":1354},[1349,3440,1480],{"class":1358},[1349,3442,1972],{"class":1362},[1349,3444,1366],{"class":1354},[1349,3446,3447],{"class":1369},"\"addNum\"",[1349,3449,1483],{"class":1362},[1349,3451,1366],{"class":1354},[1349,3453,1488],{"class":1369},[1349,3455,3456],{"class":1354},">使用子組件 addNum 增加子組件 childCount 變數值\u003C\u002F",[1349,3458,1480],{"class":1358},[1349,3460,1396],{"class":1354},[1216,3462,3463,3464,3467,3468,3471,3472,3475],{},"⭐ 【 取得子組件的響應試變數值 】按鈕可以取得子組件",[1260,3465,3466],{},"childCount","當前變數值。",[3469,3470],"br",{},"\n⭐ 【 使用子組件 addNum 讓子組件 childCount 變數值 + 1 】按鈕可以取得子組件",[1260,3473,3474],{},"addNum"," 函數，並且將子組件 childCount 變數值 + 1。",[1216,3477,3478],{},"父組件 javascript：",[1340,3480,3482],{"className":1691,"code":3481,"language":1693,"meta":1345,"style":1345},"const rootComponent = {\n  data() {\n    return {\n      RootCount: 0\n    };\n  },\n  methods: {\n    \u002F\u002F 取得子組件數據 childCount\n    getChildCount() {\n      this.RootCount = this.$refs.child.childCount;\n    },\n    \u002F\u002F 使用子組件內的 addNum 方法\n    addNum() {\n      this.$refs.child.addNum();\n    }\n  },\n  components: {\n    childComponent\n  }\n};\n",[1260,3483,3484,3494,3500,3506,3514,3518,3522,3526,3531,3538,3552,3556,3561,3568,3579,3583,3587,3592,3597,3601],{"__ignoreMap":1345},[1349,3485,3486,3488,3490,3492],{"class":1351,"line":340},[1349,3487,1029],{"class":1700},[1349,3489,2337],{"class":1703},[1349,3491,1707],{"class":1700},[1349,3493,2342],{"class":1354},[1349,3495,3496,3498],{"class":1351,"line":329},[1349,3497,2347],{"class":1716},[1349,3499,2350],{"class":1354},[1349,3501,3502,3504],{"class":1351,"line":318},[1349,3503,2355],{"class":1700},[1349,3505,2342],{"class":1354},[1349,3507,3508,3511],{"class":1351,"line":134},[1349,3509,3510],{"class":1354},"      RootCount: ",[1349,3512,3513],{"class":1703},"0\n",[1349,3515,3516],{"class":1351,"line":122},[1349,3517,2370],{"class":1354},[1349,3519,3520],{"class":1351,"line":31},[1349,3521,2375],{"class":1354},[1349,3523,3524],{"class":1351,"line":17},[1349,3525,2380],{"class":1354},[1349,3527,3528],{"class":1351,"line":110},[1349,3529,3530],{"class":1742},"    \u002F\u002F 取得子組件數據 childCount\n",[1349,3532,3533,3536],{"class":1351,"line":76},[1349,3534,3535],{"class":1716},"    getChildCount",[1349,3537,2350],{"class":1354},[1349,3539,3540,3542,3545,3547,3549],{"class":1351,"line":247},[1349,3541,2397],{"class":1703},[1349,3543,3544],{"class":1354},".RootCount ",[1349,3546,1366],{"class":1700},[1349,3548,2832],{"class":1703},[1349,3550,3551],{"class":1354},".$refs.child.childCount;\n",[1349,3553,3554],{"class":1351,"line":236},[1349,3555,2409],{"class":1354},[1349,3557,3558],{"class":1351,"line":225},[1349,3559,3560],{"class":1742},"    \u002F\u002F 使用子組件內的 addNum 方法\n",[1349,3562,3563,3566],{"class":1351,"line":214},[1349,3564,3565],{"class":1716},"    addNum",[1349,3567,2350],{"class":1354},[1349,3569,3570,3572,3575,3577],{"class":1351,"line":203},[1349,3571,2397],{"class":1703},[1349,3573,3574],{"class":1354},".$refs.child.",[1349,3576,3474],{"class":1716},[1349,3578,1787],{"class":1354},[1349,3580,3581],{"class":1351,"line":192},[1349,3582,2436],{"class":1354},[1349,3584,3585],{"class":1351,"line":181},[1349,3586,2375],{"class":1354},[1349,3588,3589],{"class":1351,"line":170},[1349,3590,3591],{"class":1354},"  components: {\n",[1349,3593,3594],{"class":1351,"line":159},[1349,3595,3596],{"class":1354},"    childComponent\n",[1349,3598,3599],{"class":1351,"line":148},[1349,3600,2475],{"class":1354},[1349,3602,3603],{"class":1351,"line":137},[1349,3604,2480],{"class":1354},[1216,3606,3607],{},"子組件 javascript：",[1340,3609,3611],{"className":1691,"code":3610,"language":1693,"meta":1345,"style":1345},"const childComponent = {\n  template: \"#childComponent\",\n  data() {\n    return {\n      \u002F\u002F 紀錄計數器當前數字\n      childCount: 0\n    };\n  },\n  methods: {\n    \u002F\u002F 將變數 childCount + 1\n    addNum() {\n      this.childCount += 1;\n    }\n  }\n};\n",[1260,3612,3613,3624,3635,3641,3647,3652,3659,3663,3667,3671,3676,3682,3697,3701,3705],{"__ignoreMap":1345},[1349,3614,3615,3617,3620,3622],{"class":1351,"line":340},[1349,3616,1029],{"class":1700},[1349,3618,3619],{"class":1703}," childComponent",[1349,3621,1707],{"class":1700},[1349,3623,2342],{"class":1354},[1349,3625,3626,3629,3632],{"class":1351,"line":329},[1349,3627,3628],{"class":1354},"  template: ",[1349,3630,3631],{"class":1369},"\"#childComponent\"",[1349,3633,3634],{"class":1354},",\n",[1349,3636,3637,3639],{"class":1351,"line":318},[1349,3638,2347],{"class":1716},[1349,3640,2350],{"class":1354},[1349,3642,3643,3645],{"class":1351,"line":134},[1349,3644,2355],{"class":1700},[1349,3646,2342],{"class":1354},[1349,3648,3649],{"class":1351,"line":122},[1349,3650,3651],{"class":1742},"      \u002F\u002F 紀錄計數器當前數字\n",[1349,3653,3654,3657],{"class":1351,"line":31},[1349,3655,3656],{"class":1354},"      childCount: ",[1349,3658,3513],{"class":1703},[1349,3660,3661],{"class":1351,"line":17},[1349,3662,2370],{"class":1354},[1349,3664,3665],{"class":1351,"line":110},[1349,3666,2375],{"class":1354},[1349,3668,3669],{"class":1351,"line":76},[1349,3670,2380],{"class":1354},[1349,3672,3673],{"class":1351,"line":247},[1349,3674,3675],{"class":1742},"    \u002F\u002F 將變數 childCount + 1\n",[1349,3677,3678,3680],{"class":1351,"line":236},[1349,3679,3565],{"class":1716},[1349,3681,2350],{"class":1354},[1349,3683,3684,3686,3689,3692,3695],{"class":1351,"line":225},[1349,3685,2397],{"class":1703},[1349,3687,3688],{"class":1354},".childCount ",[1349,3690,3691],{"class":1700},"+=",[1349,3693,3694],{"class":1703}," 1",[1349,3696,2806],{"class":1354},[1349,3698,3699],{"class":1351,"line":214},[1349,3700,2436],{"class":1354},[1349,3702,3703],{"class":1351,"line":203},[1349,3704,2475],{"class":1354},[1349,3706,3707],{"class":1351,"line":192},[1349,3708,2480],{"class":1354},[1250,3710],{},[1216,3712,3713,3714,3717,3718,3720],{},"如果希望限制子組件實例中哪些數據和方法可以被外部訪問，可以在子組件中使用",[1260,3715,3716],{},"expose 選項","，來控制外層透過",[1260,3719,3033],{},"能夠讀取的範圍。",[1216,3722,3723,3724,3727,3728,3730,3731,3733],{},"以上面的案例為例，可以使用",[1260,3725,3726],{},"expose","選項來限制只有",[1260,3729,3474],{},"方法能被外部通過 ref 屬性訪問，而子組件的數據",[1260,3732,3466],{},"則無法被外部讀取。",[1216,3735,3736,3737,3740,3741,3743,3744,3051],{},"當呼叫根組件",[1260,3738,3739],{},"getChildCount","方法試圖取得子組件",[1260,3742,3466],{},"參數的時候，會回傳",[1260,3745,2489],{},[1216,3747,1328,3748],{},[1330,3749,3752],{"href":3750,"rel":3751},"https:\u002F\u002Fcodepen.io\u002Fgwhvusel-the-builder\u002Fpen\u002FoNrMqZv",[1334],"Vue3 Options API ref 取得組件實體內數據及方法(搭配 expose 限制)實作連結",[1216,3754,1688],{},[1340,3756,3758],{"className":1691,"code":3757,"language":1693,"meta":1345,"style":1345},"const childComponent = {\n  expose: [\"addNum\"],\n  template: \"#childComponent\",\n  data() {\n    return {\n      \u002F\u002F 紀錄計數器當前數字\n      childCount: 0\n    };\n  },\n  methods: {\n    \u002F\u002F 將變數 childCount + 1\n    addNum() {\n      this.childCount += 1;\n    }\n  }\n};\n",[1260,3759,3760,3770,3780,3788,3794,3800,3804,3810,3814,3818,3822,3826,3832,3844,3848,3852],{"__ignoreMap":1345},[1349,3761,3762,3764,3766,3768],{"class":1351,"line":340},[1349,3763,1029],{"class":1700},[1349,3765,3619],{"class":1703},[1349,3767,1707],{"class":1700},[1349,3769,2342],{"class":1354},[1349,3771,3772,3775,3777],{"class":1351,"line":329},[1349,3773,3774],{"class":1354},"  expose: [",[1349,3776,3447],{"class":1369},[1349,3778,3779],{"class":1354},"],\n",[1349,3781,3782,3784,3786],{"class":1351,"line":318},[1349,3783,3628],{"class":1354},[1349,3785,3631],{"class":1369},[1349,3787,3634],{"class":1354},[1349,3789,3790,3792],{"class":1351,"line":134},[1349,3791,2347],{"class":1716},[1349,3793,2350],{"class":1354},[1349,3795,3796,3798],{"class":1351,"line":122},[1349,3797,2355],{"class":1700},[1349,3799,2342],{"class":1354},[1349,3801,3802],{"class":1351,"line":31},[1349,3803,3651],{"class":1742},[1349,3805,3806,3808],{"class":1351,"line":17},[1349,3807,3656],{"class":1354},[1349,3809,3513],{"class":1703},[1349,3811,3812],{"class":1351,"line":110},[1349,3813,2370],{"class":1354},[1349,3815,3816],{"class":1351,"line":76},[1349,3817,2375],{"class":1354},[1349,3819,3820],{"class":1351,"line":247},[1349,3821,2380],{"class":1354},[1349,3823,3824],{"class":1351,"line":236},[1349,3825,3675],{"class":1742},[1349,3827,3828,3830],{"class":1351,"line":225},[1349,3829,3565],{"class":1716},[1349,3831,2350],{"class":1354},[1349,3833,3834,3836,3838,3840,3842],{"class":1351,"line":214},[1349,3835,2397],{"class":1703},[1349,3837,3688],{"class":1354},[1349,3839,3691],{"class":1700},[1349,3841,3694],{"class":1703},[1349,3843,2806],{"class":1354},[1349,3845,3846],{"class":1351,"line":203},[1349,3847,2436],{"class":1354},[1349,3849,3850],{"class":1351,"line":192},[1349,3851,2475],{"class":1354},[1349,3853,3854],{"class":1351,"line":181},[1349,3855,2480],{"class":1354},[1253,3857,3858],{"id":3858},"結論",[1228,3860,3861,3878,3894,3913],{},[1231,3862,3863,3867,3868,3871,3872,3874,3875,3877],{},[3864,3865,3866],"strong",{},"第三方套件與 Web API 的應用","：當需要對",[1260,3869,3870],{},"HTML 元素","進行操作時，可以使用 Vue 的",[1260,3873,3033],{},"來標記對應的",[1260,3876,3327],{},"，方便與第三方套件或 Web API 結合使用。",[1231,3879,3880,3883,3884,3887,3888,3890,3891,3893],{},[3864,3881,3882],{},"v-for 搭配 ref 屬性","：在使用",[1260,3885,3886],{},"v-for","生成多個元素時，可以使用",[1260,3889,3033],{},"來將這些元素存儲為一個",[1260,3892,2859],{},"，便於後續進行批次操作。",[1231,3895,3896,3898,3899,3902,3903,3906,3907,3910,3911,3051],{},[3864,3897,1242],{},"：可以透過",[1260,3900,3901],{},"函","數的方式",[1260,3904,3905],{},"動態綁定 ref","，在需要時對原生 HTML 元素進行操作。當綁定的元素或組件被銷毀時，函數中的",[1260,3908,3909],{},"ref 參數","會自動變為",[1260,3912,3050],{},[1231,3914,3915,3918,3919],{},[3864,3916,3917],{},"父組件透過 ref 屬性讀取子組件的數據及方法","：\n",[1228,3920,3921,3928],{},[1231,3922,3923,3924,3927],{},"在父組件中，可以通過",[1260,3925,3926],{},"ref 綁定子組件實例","，直接訪問子組件內部的變數或調用其方法。需要注意的是，這種操作可能會導致資料流的混亂，因此應謹慎使用。",[1231,3929,3930,3931,3933,3934,3937],{},"如果子組件需要限制父組件通過",[1260,3932,3033],{},"訪問內部數據和方法的範圍，可以使用",[1260,3935,3936],{},"expose 參數","來定義哪些數據和方法可以被外部訪問。",[3939,3940,3941],"style",{},"html pre.shiki code .sYgZi, html code.shiki .sYgZi{--shiki-default:#24292E;--shiki-dark:#ADBAC7}html pre.shiki code .sIAta, html code.shiki .sIAta{--shiki-default:#22863A;--shiki-dark:#8DDB8C}html pre.shiki code .sMOND, html code.shiki .sMOND{--shiki-default:#6F42C1;--shiki-dark:#6CB6FF}html pre.shiki code .s-HuK, html code.shiki .s-HuK{--shiki-default:#032F62;--shiki-dark:#96D0FF}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html pre.shiki code .s7YZ4, html code.shiki .s7YZ4{--shiki-default:#D73A49;--shiki-dark:#F47067}html pre.shiki code .sviXB, html code.shiki .sviXB{--shiki-default:#005CC5;--shiki-dark:#6CB6FF}html pre.shiki code .sPO5f, html code.shiki .sPO5f{--shiki-default:#6F42C1;--shiki-dark:#DCBDFB}html pre.shiki code .sDN9O, html code.shiki .sDN9O{--shiki-default:#6A737D;--shiki-dark:#768390}html pre.shiki code .sOLd2, html code.shiki .sOLd2{--shiki-default:#6F42C1;--shiki-dark:#F69D50}",{"title":1345,"searchDepth":134,"depth":134,"links":3943},[3944],{"id":1226,"depth":329,"text":1226,"children":3945},[3946,3947,3948,3949,3950,3951],{"id":1255,"depth":318,"text":1233},{"id":2497,"depth":318,"text":2498},{"id":2846,"depth":318,"text":1239},{"id":3037,"depth":318,"text":1242},{"id":3318,"depth":318,"text":1245},{"id":3858,"depth":318,"text":3858},[11,713],"md",{},"---\ntitle: \"Vue 3 用實作帶你看過核心概念 - Day 16：使用 ref 屬性引用模板元素\"\ndate: 2024-09-29 16:25:45\ntags:\n  - \"iThome 鐵人賽\"\n  - \"2024 鐵人賽\"\n  - \"Vue 3\"\n  - \"Options API\"\ncategories:\n  - \"iThome 鐵人賽\"\n  - \"Vue\"\ndescription: \"雖然 Vue 透過模板幫助我們處理了大部分的DOM 操作，但在某些情況下，仍然需要手動操作 DOM。例如，在使用第三方套件（如 Bootstrap 的 Modal）時，或者需要調用像video.play()和video.…\"\ncanonical: https:\u002F\u002Fithelp.ithome.com.tw\u002Farticles\u002F10360419\nseries:\n  name: \"2024 iThome 鐵人賽：Vue 3 初學者：用實作帶你看過核心概念\"\n  url: https:\u002F\u002Fithelp.ithome.com.tw\u002Fusers\u002F20116554\u002Fironman\u002F7800\n  day: 16\n---\n\n![文章背景圖](https:\u002F\u002Fres.cloudinary.com\u002Fdseg0uwc9\u002Fimage\u002Fupload\u002Fv1727592415\u002F2024%20%E9%90%B5%E4%BA%BA%E8%B3%BD\u002FDay%2016%EF%BC%9A%E6%A8%A1%E6%9D%BF%E5%BC%95%E7%94%A8%28ref%29\u002FDay_16_%E4%BD%BF%E7%94%A8_ref_%E5%B1%AC%E6%80%A7%E5%BC%95%E7%94%A8%E6%A8%A1%E6%9D%BF%E5%85%83%E7%B4%A0_vgnlzg.png)\n\n## 目錄\n\n- ref 屬性搭配第三方 Boostrap Modal 使用\n- ref 屬性搭配 Video Web API 使用\n- v-for 搭配陣列儲存 ref 屬性使用\n- 動態 ref 屬性綁定方法\n- 組件實例搭配 ref 使用\n- 總結\n\n* * *\n\n### ref 屬性搭配第三方 Boostrap Modal 使用\n\n雖然 Vue 透過模板幫助我們處理了大部分的`DOM 操作`，但在某些情況下，仍然需要手動操作 DOM。例如，在使用第三方套件（如 Bootstrap 的 Modal）時，或者需要調用像`video.play()`和`video.pause()`這類的`原生 Web API` 時，我們必須直接與 DOM 元素進行交互。此時，可以使用`ref`屬性為`DOM 元素設置標記`，以便方便地引用並手動操作這些元素。\n\n觀察`Bootstrap`的`Modal 組件`可以發現，若要使用 JavaScript 來控制 Modal，需要先創建一個 Bootstrap Modal 的實例，並將對應的 Modal 元素 ID 傳遞給這個實例。完成這一步後，就可以透過 `modal.show()`或`modal.hide()`這樣的方法來控制 Modal 的開啟和關閉。\n\n原生的 Boostrap Modal 使用流程說明：\n\n1. 初始化透過`Boostrap`實例綁定對應顯示的 Modal DOM 元素。\n2. 監聽 Modal 內的儲存(Save)按鈕跟關閉(Close)按鈕，點擊的時候觸發對應的方法`show()`和`hide()`方法。\n\n👉 [Boostrap Modal 純 javaScript 寫法實作連結](https:\u002F\u002Fcodepen.io\u002Fgwhvusel-the-builder\u002Fpen\u002FXWLBXgX)\n\nHTML：\n\n```html\n  \u003Cdiv class=\"modal\" tabindex=\"-1\" role=\"dialog\" id=\"modal\">\n    \u003Cdiv class=\"modal-dialog\" role=\"document\">\n      \u003Cdiv class=\"modal-content\">\n        \u003Cdiv class=\"modal-header\">\n          \u003Ch5 class=\"modal-title\">Modal title\u003C\u002Fh5>\n          \u003Cbutton type=\"button\" class=\"btn-close\" data-bs-dismiss=\"modal\" aria-label=\"Close\">\u003C\u002Fbutton>\n        \u003C\u002Fdiv>\n        \u003Cdiv class=\"modal-body\">\n          \u003Cp>Modal body text goes here.\u003C\u002Fp>\n        \u003C\u002Fdiv>\n        \u003Cdiv class=\"modal-footer\">\n          \u003Cbutton id=\"saveButton\" type=\"button\" class=\"btn btn-primary\">Save changes\u003C\u002Fbutton>\n          \u003Cbutton id=\"closeButton\" type=\"button\" class=\"btn btn-secondary\" data-dismiss=\"modal\">Close\u003C\u002Fbutton>\n        \u003C\u002Fdiv>\n      \u003C\u002Fdiv>\n    \u003C\u002Fdiv>\n  \u003C\u002Fdiv>\n```\n\njavascript：\n\n```javascript\nconst myModal = new bootstrap.Modal(document.getElementById(\"modal\"));\n\n\u002F\u002F 開啟 Modal 按鈕\ndocument.querySelector(\"#openModal\").addEventListener(\"click\", function () {\n  myModal.show();\n});\n\n\u002F\u002F Modal 儲存按鈕\ndocument.querySelector(\"#saveButton\").addEventListener(\"click\", function () {\n  myModal.hide();\n});\n\n\u002F\u002F Modal 關閉按鈕\ndocument.querySelector(\"#closeButton\").addEventListener(\"click\", function () {\n  myModal.hide();\n});\n```\n\n* * *\n\n接著我們將上面的控制方式改成使用 Vue 進行管控。\n\n👉 [Vue3 Options API Bootstrap Modal ref 實作連結](https:\u002F\u002Fcodepen.io\u002Fgwhvusel-the-builder\u002Fpen\u002FeYwjzaw)\n\n1. 原先透過`document.getElementById(\"modal\")`的部分取得的 DOM 元素，改成透過`ref`的方式取得。\n2. 監聽 Modal 內的儲存(Save)按鈕跟關閉(Close)按鈕，透過`v-on`綁定`click`事件，點擊的時候觸發對應的方法`show()`和`hide()`方法。\n\nVue Template：\n\n```html\n\u003Cdiv id=\"app\">\n  \u003Cdiv class=\"p-4\">\n    \u003Cbutton @click=\"openModal\" id=\"openModal\" type=\"button\" class=\"btn btn-primary\">打開 modal\u003C\u002Fbutton>\n    \u003Cdiv class=\"modal\" tabindex=\"-1\" role=\"dialog\" ref=\"modal\">\n      \u003Cdiv class=\"modal-dialog\" role=\"document\">\n        \u003Cdiv class=\"modal-content\">\n          \u003Cdiv class=\"modal-header\">\n            \u003Ch5 class=\"modal-title\">Modal title\u003C\u002Fh5>\n            \u003Cbutton type=\"button\" class=\"btn-close\" data-bs-dismiss=\"modal\" aria-label=\"Close\">\u003C\u002Fbutton>\n          \u003C\u002Fdiv>\n          \u003Cdiv class=\"modal-body\">\n            \u003Cp>Modal body text goes here.\u003C\u002Fp>\n          \u003C\u002Fdiv>\n          \u003Cdiv class=\"modal-footer\">\n            \u003Cbutton @click=\"closeModal\" id=\"saveButton\" type=\"button\" class=\"btn btn-primary\">Save changes\u003C\u002Fbutton>\n            \u003Cbutton @click=\"closeModal\" id=\"closeButton\" type=\"button\" class=\"btn btn-secondary\" data-dismiss=\"modal\">Close\u003C\u002Fbutton>\n          \u003C\u002Fdiv>\n        \u003C\u002Fdiv>\n      \u003C\u002Fdiv>\n    \u003C\u002Fdiv>\n  \u003C\u002Fdiv>\n\u003C\u002Fdiv>\n```\n\njavascript：\n\n```javascript\nconst rootComponent = {\n  data() {\n    return {\n      myModal: null\n    };\n  },\n  methods: {\n    \u002F\u002F 開啟 Modal\n    openModal() {\n      this.myModal.show();\n    },\n    \u002F\u002F 關閉 Modal\n    closeModal() {\n      this.myModal.hide();\n    }\n  },\n  mounted() {\n    this.myModal = new bootstrap.Modal(this.$refs.modal);\n  }\n};\n```\n\n⭐ 預設`ref`對象會是`undefined`如果需要讀取到其對應的DOM 元素需要在`mouted`模板渲染完成之後的階段。\n\n### ref 搭配 Video Web API 使用\n\n除了上述與第三方套件搭配的案例外，在使用像`video`這類的原生 HTML 標籤時，也經常需要使用其內建的 Web API，例如：`play()`和`pause()`方法來控制播放行為。在這些情況下，可以利用 Vue 的`ref`屬性來標記這些 DOM 元素，以便進行手動控制和操作。\n\n👉 [Vue3 Options API HTML video tag with ref 實作連結](https:\u002F\u002Fcodepen.io\u002Fgwhvusel-the-builder\u002Fpen\u002FyLdqajy)\n\nVue Template：\n\n```html\n\u003Cvideo src=\"https:\u002F\u002Fwww.w3schools.com\u002Fhtml\u002Fmov_bbb.mp4\" ref='video'>\u003C\u002Fvideo>\n\u003Cdiv class=\"btn-group\" role=\"group\" aria-label=\"Basic example\">\n  \u003Cbutton @click=\"play\" type=\"button\" class=\"btn btn-secondary\">play\u003C\u002Fbutton>\n  \u003Cbutton @click=\"pause\" type=\"button\" class=\"btn btn-secondary\">pause\u003C\u002Fbutton>\n  \u003Cbutton @click=\"reset\" type=\"button\" class=\"btn btn-secondary\">reset\u003C\u002Fbutton>\n```\n\njavascript：\n\n```javascript\nconst rootComponent = {\n  data() {\n    return {\n      videoInstance: null\n    };\n  },\n  methods: {\n    play() {\n      this.videoInstance.play();\n    },\n    pause() {\n      this.videoInstance.pause();\n    },\n    reset() {\n      this.videoInstance.pause();\n      this.videoInstance.currentTime = 0;\n    }\n  },\n  mounted() {\n    this.videoInstance = this.$refs.video;\n  }\n};\n```\n\n### v-for 搭配陣列儲存 ref 屬性使用\n\n在 Vue 中，當`ref`與`v-for 指令`一起使用時，Vue 會自動將生成的 DOM 元素存儲在一個`陣列`中。可以透過`this.$refs`訪問這些元素。\n\n👉 [Vue3 Options API v-for 搭配 ref 陣列實作連結](https:\u002F\u002Fcodepen.io\u002Fgwhvusel-the-builder\u002Fpen\u002FLYKBbmX)\n\nVue Template：\n\n```html\n\u003Cul>\n  \u003Cli v-for=\"item in productList\" :key=\"item\" ref=\"items\">{{ item }}\u003C\u002Fli>\n\u003C\u002Ful>\n```\n\njavascript：\n\n```javascript\nconst app = createApp({\n  data() {\n    return {\n      productList: [\"Apple\", \"Orange\", \"Banana\"]\n    };\n  }\n  mounted() {\n    console.log(\"this.items\", this.$refs.items);\n  }\n});\n```\n\n⭐ 無法保證綁定陣列中`ref 屬性`的順序與原始陣列數據的順序一致\n\n### 動態 ref 屬性綁定方法\n\n可以透過綁定一個`動態 ref 屬性`，在每次模板更新時將該`ref`傳入到一個函數中進行處理。如果綁定的元素被銷毀，傳入函數的參數值將會自動變為`null`。\n\n流程說明：\n\n1. 透過按【切換顯示使用者帳號輸入框】按鈕切換使用者帳號輸入欄位的顯示與隱藏。\n2. 當使用者帳號輸入欄位出現時，透過`動態綁定的 ref 屬性`，自動將焦點聚焦到該輸入框，達到 focus() 效果。\n\n👉 [Vue3 Options API ref 動態綁定方法(method)實作連結](https:\u002F\u002Fcodepen.io\u002Fgwhvusel-the-builder\u002Fpen\u002FKKjBZeO)\n\n![動態綁定 ref 屬性取得元素焦點](https:\u002F\u002Fres.cloudinary.com\u002Fdseg0uwc9\u002Fimage\u002Fupload\u002Fv1727596419\u002F2024%20%E9%90%B5%E4%BA%BA%E8%B3%BD\u002FDay%2016%EF%BC%9A%E6%A8%A1%E6%9D%BF%E5%BC%95%E7%94%A8%28ref%29\u002F%E5%8B%95%E6%85%8B%E7%B6%81%E5%AE%9A_ref_%E5%B1%AC%E6%80%A7%E5%8F%96%E5%BE%97%E5%85%83%E7%B4%A0%E7%84%A6%E9%BB%9E_qtlk2t.png)\n\nVue Template：\n\n```html\n\u003Cdiv v-if=\"isShowAccount\" class=\"input-group\">\n  \u003Clabel for=\"inputAccount\">使用者帳號：\u003C\u002Flabel>\n  \u003Cinput id=\"inputAccount\" type=\"text\" :ref=\"setRef\">\n\u003C\u002Fdiv>\n\u003Cbutton @click=\"register\" type=\"button\">切換顯示使用者帳號輸入框\u003C\u002Fbutton>\n```\n\njavascript：\n\n```javascript\n  methods: {\n    setRef(ref) {\n      \u002F\u002F ref 是動態傳入的屬性\n      if (ref) {\n        this.$nextTick(() => {\n          ref.focus();\n        });\n      }\n    },\n    register() {\n      this.isShowAccount = !this.isShowAccount;\n    }\n  }\n...略\n```\n\n### 組件實例搭配 ref 使用\n\n當`ref 屬性`被應用在 HTML 元素上時，它會標記並引用實際的`HTML DOM 元素`；而當`ref 屬性`被應用在子組件上時，`ref 屬性`則會引用該`子組件的實例`。透過這個`ref 屬性`，可以直接訪問子組件的內部數據和方法。不過，過度使用`ref 屬性`來操作子組件的資料和行為，可能會導致資料流混亂，需要謹慎使用。\n\n流程說明：\n\n1. 子組件定義了一個計數器，使用變數 childCount 來記錄當前的計數值，並提供 addNum 方法來增加 childCount 的值，每次增加 1。\n2. 在根組件中，透過 ref 屬性標記子組件的實例，並定義 getChildCount 方法來獲取子組件當前的 childCount 值，以及 addNum 方法來觸發子組件內部的 addNum 方法。\n\n![父組件透過 ref 屬性讀取子組件屬性及使用其方法](https:\u002F\u002Fres.cloudinary.com\u002Fdseg0uwc9\u002Fimage\u002Fupload\u002Fv1727661063\u002F2024%20%E9%90%B5%E4%BA%BA%E8%B3%BD\u002FDay%2016%EF%BC%9A%E6%A8%A1%E6%9D%BF%E5%BC%95%E7%94%A8%28ref%29\u002F%E7%88%B6%E7%B5%84%E4%BB%B6%E9%80%8F%E9%81%8E_ref_%E4%BD%BF%E7%94%A8%E5%AD%90%E7%B5%84%E4%BB%B6%E6%96%B9%E6%B3%95%E5%8F%8A%E5%8F%96%E5%BE%97%E5%AF%A6%E4%BE%8B%E8%AE%8A%E6%95%B8%E5%80%BC_jiifwa.png)\n\n👉 [Vue3 Options API ref 取得組件實體內數據及方法實作連結](https:\u002F\u002Fcodepen.io\u002Fgwhvusel-the-builder\u002Fpen\u002FxxoJYLW)\n\n父組件 Vue Template：\n\n```html\n\u003Cchild-component ref=\"child\">\u003C\u002Fchild-component>\n\u003Cp>取得子組件的響應式變數值：{{ RootCount }}\u003C\u002Fp>\n\u003Cbutton @click=\"getChildCount\" type=\"button\">取得子組件的響應試變數值\u003C\u002Fbutton>\n\u003Cbutton @click=\"addNum\" type=\"button\">使用子組件 addNum 增加子組件 childCount 變數值\u003C\u002Fbutton>\n```\n\n⭐ 【 取得子組件的響應試變數值 】按鈕可以取得子組件`childCount`當前變數值。  \n⭐ 【 使用子組件 addNum 讓子組件 childCount 變數值 + 1 】按鈕可以取得子組件`addNum` 函數，並且將子組件 childCount 變數值 + 1。\n\n父組件 javascript：\n\n```javascript\nconst rootComponent = {\n  data() {\n    return {\n      RootCount: 0\n    };\n  },\n  methods: {\n    \u002F\u002F 取得子組件數據 childCount\n    getChildCount() {\n      this.RootCount = this.$refs.child.childCount;\n    },\n    \u002F\u002F 使用子組件內的 addNum 方法\n    addNum() {\n      this.$refs.child.addNum();\n    }\n  },\n  components: {\n    childComponent\n  }\n};\n```\n\n子組件 javascript：\n\n```javascript\nconst childComponent = {\n  template: \"#childComponent\",\n  data() {\n    return {\n      \u002F\u002F 紀錄計數器當前數字\n      childCount: 0\n    };\n  },\n  methods: {\n    \u002F\u002F 將變數 childCount + 1\n    addNum() {\n      this.childCount += 1;\n    }\n  }\n};\n```\n\n* * *\n\n如果希望限制子組件實例中哪些數據和方法可以被外部訪問，可以在子組件中使用`expose 選項`，來控制外層透過`ref 屬性`能夠讀取的範圍。\n\n以上面的案例為例，可以使用`expose`選項來限制只有`addNum`方法能被外部通過 ref 屬性訪問，而子組件的數據`childCount`則無法被外部讀取。\n\n當呼叫根組件`getChildCount`方法試圖取得子組件`childCount`參數的時候，會回傳`undefined`。\n\n👉 [Vue3 Options API ref 取得組件實體內數據及方法(搭配 expose 限制)實作連結](https:\u002F\u002Fcodepen.io\u002Fgwhvusel-the-builder\u002Fpen\u002FoNrMqZv)\n\njavascript：\n\n```javascript\nconst childComponent = {\n  expose: [\"addNum\"],\n  template: \"#childComponent\",\n  data() {\n    return {\n      \u002F\u002F 紀錄計數器當前數字\n      childCount: 0\n    };\n  },\n  methods: {\n    \u002F\u002F 將變數 childCount + 1\n    addNum() {\n      this.childCount += 1;\n    }\n  }\n};\n```\n\n### 結論\n\n- **第三方套件與 Web API 的應用**：當需要對`HTML 元素`進行操作時，可以使用 Vue 的`ref 屬性`來標記對應的`HTML DOM 元素`，方便與第三方套件或 Web API 結合使用。\n- **v-for 搭配 ref 屬性**：在使用`v-for`生成多個元素時，可以使用`ref 屬性`來將這些元素存儲為一個`陣列`，便於後續進行批次操作。\n- **動態 ref 屬性綁定方法**：可以透過`函`數的方式`動態綁定 ref`，在需要時對原生 HTML 元素進行操作。當綁定的元素或組件被銷毀時，函數中的`ref 參數`會自動變為`null`。\n- **父組件透過 ref 屬性讀取子組件的數據及方法**：\n    - 在父組件中，可以通過`ref 綁定子組件實例`，直接訪問子組件內部的變數或調用其方法。需要注意的是，這種操作可能會導致資料流的混亂，因此應謹慎使用。\n    - 如果子組件需要限制父組件通過`ref 屬性`訪問內部數據和方法的範圍，可以使用`expose 參數`來定義哪些數據和方法可以被外部訪問。\n",{"title":854,"description":855},{"name":717,"url":718,"day":181},{"loc":853,"images":3959,"lastmod":856},[3960,3961,3962],{"loc":1222},{"loc":3079},{"loc":3360},"ithome-2024-day-16","2024-09-29-ithome-2024-day-16",[11,710,711,725],"yXT0Dns3JorZ-BCX2uRZvgPJxiPXIka4lEyj0EyR27k",1792575205278]