Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
about-vue-hooks.pdf
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
sunecosuri
January 30, 2019
770
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
about-vue-hooks.pdf
sunecosuri
January 30, 2019
More Decks by sunecosuri
See All by sunecosuri
New in Go 1.26 Implementing go fix in product development
sunecosuri
0
690
'Securing Web Apps with Modern Platform Features' を意訳してみる / Translate Securing Web Apps with Modern Platform Features
sunecosuri
2
390
Vue.js × TypeScript でclass style componentを廃止した話 / migrated-class-style-component -for-vuejs-and-typescrpit
sunecosuri
2
4.4k
Nuxt.js のbuid速度が早くなるオプションのいくつかについて / Increase-build-speed-for-Nuxt.js
sunecosuri
1
1.4k
Nuxt.js におけるCSPの連携について / content security policy for Nuxt.js
sunecosuri
0
2.6k
ロリポップマネージドクラウドでAlexaスキルを開発しよう / let's development alexa skill by lolipop managed cloud
sunecosuri
1
240
マネージドクラウドのリリース速度を上げるお話 / Increase release speed for managed cloud
sunecosuri
2
370
Reconsider Content Security Policy for WEB Application
sunecosuri
0
120
Featured
See All Featured
Getting science done with accelerated Python computing platforms
jacobtomlinson
2
240
The Spectacular Lies of Maps
axbom
PRO
1
820
Art, The Web, and Tiny UX
lynnandtonic
304
22k
Digital Ethics as a Driver of Design Innovation
axbom
PRO
1
320
Reflections from 52 weeks, 52 projects
jeffersonlam
356
21k
Principles of Awesome APIs and How to Build Them.
keavy
128
18k
Practical Orchestrator
shlominoach
191
11k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
162
16k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
32
2.9k
Kristin Tynski - Automating Marketing Tasks With AI
techseoconnect
PRO
0
280
The Art of Programming - Codeland 2020
erikaheidi
57
14k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
31
3.2k
Transcript
Vue-hooks Vue hooks ʹ͍ͭͯ @sunecosuri Date: 2019-01-30 Vue Night in
Fukuoka #2
@sunecosuri(Narumi Kouki) GMOϖύϘΤϯδχΞ ϚΠϒʔϜɿ ϝϧνϟϦܯʢ์ஔࣗసंΛ͢ʣ Ͱ͔͍ʢେެԂʣۙͰ͔Θ͍͍ݘʹରͯ͠৮Βͤͯ͘Εͱֻ͚ࣄҊ
͢͜ͱ Vue-hooks ʹ͍ͭͯ ෦࣮ʹ͍ͭͯ React-hooks ʹ͍ͭͯ mixin ʹ͍ͭͯ
Vue hooks Vue hooks
Vue hooks Vue Hooks Evan You(Vueͷ։ൃऀ)͞ΜͷVueͰ React hooks ͷΑ͏ʹ࣮͞Ε͍ͯΔ࣮ݧతͳϦϙδτϦ ※
͢Ͱʹnpm publish ͞Ε͍ͯΔ͕production ೖඇਪͱͷ͜ͱʢݱ࣌Ͱ0.3.2ʣ
React hooks React hooks
React hooks React Hooks ReactͰStateful ͳίϯϙʔωϯτΛॻ͘ࡍɺClass ComponentΛΘͳ͚ΕͳΒͳ͔͕ͬͨ State Λ Functional
Component Ͱѻ͑ΔΑ͏ʹͨ͠ͷ
ͳʹ͕͍͍ͷʁ
ͳʹ͕͍͍ͷ͔ Vue ͷ ݱࡏͷAPI ʹมΘΔͷͱݴ͏ΑΓɺMixin ͷҙຯ߹͍ʹ͍ۙ
Mixin Mixin ί ϯ ϙ ʔ ω ϯ τ ʹ
ڞ ௨ ػ ೳ Λ Ճ ͢ Δ Έ - methods ʹڞ௨ؔͷՃ - lifecycle hook ʹ͓͚Δॲཧͷڞ௨Խ - created ͳͲͷϥΠϑαΠΫϧϑοΫʹڞ௨ॲཧՃ ϥΠϑαΠΫϧϝιουϛοΫεΠϯˠίϯϙʔωϯτͷॱʹ࣮ߦ͞ΕΔ - namespace͕ڝ߹ͨ͠ࡍίϯϙʔωϯτଆ͕༏ઌతʹ࣮ߦ͞ΕΔ ʢৼΔ͍తʹ্ॻ͖Ͱͳ͘Mergeʣ - ίϯϙʔωϯτʹΦϓγϣϯͷΑ͏ͳܗͰࠞͥࠐ·ΕΔ ※্هͷΑ͏ʹॻ͘ͱɺϩʔυ࣌ʹ ‘loaded mixin’ -> ’loaded main’ͷॱͰग़ྗ͞ΕΔ
mirin mixin ͷσϝϦοτ ҉ త ͳ ڍ ಈ ʹ
ͳ Γ ͢ ͍ ͨ Ί ɺ ό ά Λ ੜ Έ ͩ ͠ ͢ ͍ Օ ॴ ʹ ͳ Γ ͢ ͍ m i x i n Ͱ ڞ ௨ Խ ͠ ͯ ί ʔ υ Λ ͠ ͯ ͍ Δ ͷ ʹ ɺ ؔ ৺ ͞ Ε ʹ ͘͘ ͳ Γ ͕ ͪ ͳ ͷ Ͱ ໋ ໊ ॲ ཧ ͦ ͷ ͷ Λ ҙ ࣝ ͠ ͨ Γ ͢ Δ ඞ ཁ ͕ ͋ Δ
Vue Hooks API Vue Hooks API API໊ ༰ useEffect ϥΠϑαΠΫϧΠϕϯτΛ࣮ݱ͢ΔجװͱͳΔAPI
useRef Instance.$refs Λฦ͢ useData localStateΛఆٛ Vueͷdata૬ instance.$set() Ͱ࣮ useMounted useEffectΛੜͤͯ͞mounted()Λ࣮ useDestroyed useEffectΛੜͤͯ͞destroyed()Λ࣮ useUpdated useEffectΛੜͤͯ͞updated()Λ࣮ useWatch instance.$watch Λ෦Ͱ࣮ߦͯ͠ҾΛฦ͢ useComputed instance.$watch Λ෦Ͱ࣮ߦͯ͠ɹinstance. _computedStore Λฦ͢ withHooks ͜ͷؔʹ͞ΕͨؔͰͷΈ্هͷHookΛݺͼग़͢͜ͱ͕Ͱ͖Δ
͜Μͳ෩ʹॻ͚Δ (ΧελϜϑοΫver) 1. vue-hooks͔Β ར༻͢Δ hooks Λ import 2. useComputed,
useWatch, useMountedͱ͔Λ༻͍ͯదٓॲཧΛՃ 3. ΧελϜϑοΫΛఆٛ͢Δ 4. hooks() ෦ͰΧελϜϑοΫͷฦΓΛฦ͢ 5. render method ෦ͰwithHooks ͷΓʢΧελϜϑοΫʣΛݺͼग़͢
͜Μͳ෩ʹॻ͚Δ (ैདྷͷVueίϯϙʔωϯτver) 1. vue-hooks͔Β ར༻͢Δ hooks Λ import 2. useDataΛͬͯΦϒδΣΫτͷܗͰఆٛ͢Δ
3. hooks() ෦ͰuseComputed, useWatch, useMountedͱ͔Λ༻͍ͯద ٓॲཧΛՃ 4. templateଆͰར༻͢ΔΛreturn͢Δ
Demo Demo
ײ ͱ ·ͱΊ - Vue3.X ͰVueMixin ͔Β Vue hooks APIʹஔ͖͑Δ͜ͱΛલ͖ʹݕ౼ͯͦ͠͏
- Hooks ΛͬͯίϯϙʔωϯτΛؔԽ͢Δ͜ͱͰείʔϓΛԚ͞ͳ͍ - useEffects() Λ͏ͱΑΓॊೈʹΧελϜϑοΫΛͰ͖ͯڞ௨ͷϩδοΫॲཧΛؔͱ ͯ͢͠Δ͜ͱ͕Ͱ͖ͦ͏ ʢͱ͍͑React hooksྗ͕ͳ͍ͷͰɺڧ͍ํੋඇڭ͍͑ͯͩ͘͞ʂʣ - ࢀߟ: https://qiita.com/c6h4clch3_gh/items/424a6ceba8148456ae67
Thanks Thanks!