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
about-vue-hooks.pdf
Search
sunecosuri
January 30, 2019
790
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
870
'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
世界の人気アプリ100個を分析して見えたペイウォール設計の心得
akihiro_kokubo
PRO
74
42k
Bioeconomy Workshop: Dr. Julius Ecuru, Opportunities for a Bioeconomy in West Africa
akademiya2063
PRO
1
360
Into the Great Unknown - MozCon
thekraken
41
2.7k
How to build an LLM SEO readiness audit: a practical framework
nmsamuel
1
910
Ecommerce SEO: The Keys for Success Now & Beyond - #SERPConf2024
aleyda
1
2.2k
Agile Actions for Facilitating Distributed Teams - ADO2019
mkilby
0
280
<Decoding/> the Language of Devs - We Love SEO 2024
nikkihalliwell
1
330
Paper Plane
katiecoart
PRO
4
53k
Have SEOs Ruined the Internet? - User Awareness of SEO in 2025
akashhashmi
0
500
Stewardship and Sustainability of Urban and Community Forests
pwiseman
0
520
Optimising Largest Contentful Paint
csswizardry
37
4k
Amusing Abliteration
ianozsvald
1
300
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!