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
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
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
780
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
850
'Securing Web Apps with Modern Platform Features' を意訳してみる / Translate Securing Web Apps with Modern Platform Features
sunecosuri
2
400
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
250
マネージドクラウドのリリース速度を上げるお話 / Increase release speed for managed cloud
sunecosuri
2
370
Reconsider Content Security Policy for WEB Application
sunecosuri
0
130
Featured
See All Featured
[SF Ruby Conf 2025] Rails X
palkan
2
1.4k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
35
3.8k
Future Trends and Review - Lecture 12 - Web Technologies (1019888BNR)
signer
PRO
0
3.7k
Measuring Dark Social's Impact On Conversion and Attribution
stephenakadiri
2
270
Done Done
chrislema
186
16k
Organizational Design Perspectives: An Ontology of Organizational Design Elements
kimpetersen
PRO
1
820
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
10
1.3k
How to build a perfect <img>
jonoalderson
1
6k
The Anti-SEO Checklist Checklist. Pubcon Cyber Week
ryanjones
0
230
Thoughts on Productivity
jonyablonski
76
5.4k
Paper Plane
katiecoart
PRO
2
53k
How Software Deployment tools have changed in the past 20 years
geshan
1
34k
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!