Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
初探 Vue 3.0 Function API
Search
Kuro Hsu
August 06, 2019
Programming
3.1k
4
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
初探 Vue 3.0 Function API
v-tw meetup #03 @ LINE TW
2019/08/06
Kuro Hsu
August 06, 2019
More Decks by Kuro Hsu
See All by Kuro Hsu
Laravel x Vite
kurotanshi
0
720
[.NET Conf 2020 Taiwan] 以輕前端視角進入 Vue 3.0 的世界
kurotanshi
0
820
[MOPCON 2020] vite: Make web dev fast again
kurotanshi
0
2.5k
[ModernWeb'20] Vue.js :The Bad Parts
kurotanshi
1
230
[MOPCON 2019] Vue.js 3.0 與 Composition API 的變革
kurotanshi
1
1.4k
[JSDC2019] 我有一堆選擇 Vue 開發框架的理由
kurotanshi
1
890
[COSCUP 2019] 前端工程師的養成之路與開源工具
kurotanshi
3
490
CSS 不是我們想像的這麼簡單! [台北場]
kurotanshi
10
2.8k
VueJS Style Guide 導讀
kurotanshi
6
1.9k
Other Decks in Programming
See All in Programming
コーディング自動化の次へ。人の介入をゼロにするファクトリーとサポートAIによる実践
timakin
1
1.5k
個人開発者よ、Honoを使え(おじさんver)
tanahiro2010
2
250
AI主導のプログラミング学習アプリを作ってみた
econanringo
0
160
When benchmarks go bad - what I learned from measuring performance wrong
hollycummins
0
210
Starting & Sustaining Code-Based E2E Testing for Non-Coding QA Teams( #jasstniigata )
teyamagu
PRO
1
980
HTML-in-Canvasで作る未来のWeb UI表現
clockmaker
4
4.8k
C#の現在地 進化の歴史と、AI時代の.NET Everywhere
neuecc
5
5.1k
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
650
sbt 2.0: takeoff
eed3si9n
0
150
ActionController meets Protocol Buffers
sorah
0
220
Compiling a real-world CLI tool to native with Static Hermes
tmikov2023
0
110
Embedded Swiftで作る自作USBデバイス によるiOSデバイスの自動テスト / iOSDC Japan 2026 glassfiber
glassfiber
0
340
Featured
See All Featured
Code Review Best Practice
trishagee
74
20k
Sam Torres - BigQuery for SEOs
techseoconnect
PRO
0
580
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
203
77k
Fireside Chat
paigeccino
43
4.1k
Typedesign – Prime Four
hannesfritz
42
3.2k
Product Roadmaps are Hard
iamctodd
55
13k
職位にかかわらず全員がリーダーシップを発揮するチーム作り / Building a team where everyone can demonstrate leadership regardless of position
madoxten
69
67k
End of SEO as We Know It (SMX Advanced Version)
ipullrank
3
4.4k
Testing 201, or: Great Expectations
jmmastey
46
8.3k
The Hidden Cost of Media on the Web [PixelPalooza 2025]
tammyeverts
2
520
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
162
16k
Transcript
初探 Vue 3.0 Function API Kuro Hsu @ LINE TW
v-tw meetup #003 2019/08/06
Kuro Hsu - Organizers of Vue.js Taiwan - https://kuro.tw -
[email protected]
- @kurotanshi
社群現況
Vue.js Taiwan https://vue.tw
超過九成的報名者在⼗十秒內 完成報名
下次的活動... 規劃中 敬請期待
關於 Vue 3.0 的進展
好消息
None
None
壞消息
None
3.0 多了了哪些新特性
Vue 3.0 RFC https://github.com/vuejs/rfcs
• ⽬目標是更更⼩小、更更快 • 加強對 TypeScript 的⽀支援 • 加強 API 設計⼀一致性
• 提⾼高可維護性 • 開放更更多底層功能
• Object.defineProperty -> Proxy API • Virtual DOM 重構 •
增強編譯時的優化 • 更更多細節請參參閱尤⼤大在 VueConf 2019 的演講: https://docs.google.com/presentation/d/ 1giA0aF6b5kljg42NUYVTB5bMxxgAc2iRVPVDo2s TirI/edit
Class API • 為了了增強與 TypeScript 的⽀支援 • 與現有 API 的相容性差異異太⼤大
• 瀏覽器對原⽣生 Class API 的⽀支援還不夠完整 • 標準對 class fields, decorators 等提案還不穩定
Class API • 為了了增強與 TypeScript 的⽀支援 • 與現有 API 的相容性差異異太⼤大
• 瀏覽器對原⽣生 Class API 的⽀支援還不夠完整 • 標準對 class fields, decorators 等提案還不穩定 CANCELED
Vue 3.0 Function-based API
• ⼜又稱 composition functions • 以「組合代替繼承」來來實作元件的複⽤用 • 更更靈活的程式邏輯複⽤用 • 對
TypeScript 的類型推導⽀支援更更好 • Tree-shaking friendly、編譯後程式碼更更容易易被壓縮 Vue 3.0 Function-based API
對比過去其他做法
Mixins
Mixins • ❌ 可能造成 Namespace 的衝突 • ❌ 從 Mixins
引入的屬性難以追蹤來來源
HOC: Higher-order Components
HOC: Higher-order Components • ❌ Props 來來源不清晰 • ❌ Props
namespace 衝突問題 • ❌ 多餘的元件實體造成性能浪費
Renderless Components
Renderless Components • ✅ 資料來來源清晰 • ✅ 無 namespace 衝突問題
• ❌ 多餘的元件實體造成性能浪費
Vue 3.0 Function- based API
• ✅ 資料來來源清晰 • ✅ 無 namespace 衝突問題 • ✅
不會產⽣生多餘的元件實體 Vue 3.0 Function-based API
None
https://github.com/vuejs/vue-function-api
Install
setup ( ) • 將共⽤用邏輯放在 setup 函式 • 第⼀一個參參數是 props
• setup( ) 內無法透過 this 存取⽬目前元件, 但可以透過第⼆二個 context 參參數取得對應 的屬性 • 最後透過 return 的物件來來與元件實體溝通
value( ) • value( ) 會為元件⽣生成⼀一個響應式 的屬性 (如同原本的 data) •
存取時透過 value( ) 的回傳 的 .value 屬性即可
state( ) • 未透過 value( ) 包裝的響應式物 件 • 意義上等同於
v2.x 的 Vue.observable( )
computed( ) • 與 v2.x computed 屬性的⾏行行爲、 作⽤用完全⼀一樣
watch( ) • 透過 watch 追蹤某個狀狀態的變化, 同時呼叫 callback function •
第⼀一個參參數是狀狀態來來源,第⼆二個則 是對應的 callback function
Lifecycle hooks • 除了了 beforeCreated 之外的 Lifecycle hook 都可以透過 onXXX
的形式來來對應 • 另外新增了了 onUnmounted
Provide / Inject • 與 v2.x 的 provide、 inject 作⽤用
完全⼀一樣。
Let’s Demo: Todo List
https://github.com/kurotanshi/vue-function-api-demo
⼤大家關⼼心的事...
轉換成本
None
在社群 激戰 討論後, 更更新後的 RFC 已取消此策略略 來源: https://github.com/vuejs/rfcs/commit/6fe6f7be06dd5982be3c57e248fcd66cd55748e0
https://suspicious-mclean-0e54c3.netlify.com/
轉換成本 === 0
• 已知 2.x -> 3.x 不會有 Breaking Change,完全相容現有 API •
新版本更更多的是底層的改寫,對多數開發者來來說沒有明顯差距 • 就是需要回饋才設有 RFC,有意⾒見見歡迎⾄至 RFC 反應
⚠ 投資⼀一定有風險,開發前應詳閱公開說明書 ⚠
Thanks