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___Vuex_のアーキテクチャ完全に理解した.pdf
Search
entaku
October 30, 2019
Programming
9.2k
8
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Vue___Vuex_のアーキテクチャ完全に理解した.pdf
entaku
October 30, 2019
More Decks by entaku
See All by entaku
Swiftでもいろんな文字_の読み上げをしたい__.pdf
entaku
0
140
AVAudioSessionの全体像を掴む.pdf
entaku
0
190
Core_Audio徹底解剖.pdf
entaku
4
450
わたしと今年のSwift.pdf
entaku
1
210
個人開発をTCAで運用していくということ.pdf
entaku
0
83
パッケージ管理でモバイル開発を安全に進める.pdf
entaku
0
1.3k
個人開発をTCAで運用していくということ.pdf
entaku
0
1.5k
技術コミュニティで技術書典出してみた.pdf
entaku
0
130
TCAでiOS開発を_学ぶ3つの利点.pdf
entaku
4
280
Other Decks in Programming
See All in Programming
Security issues being discussed on Web Platforms
petamoriken
0
730
標準パッケージに uuid が追加された 背景から見る Go らしい意思決定 / go_127_uuid_decision
convto
5
6.1k
市販E-Readerを乗っ取れ 〜Embedded Swiftで電子ペーパーガジェットを制御する〜
trickart
0
160
LL言語やWebフレームワークのPostgreSQL対応 〜DBの機能がユーザーに届くまで〜
kentaroutakeda
0
150
DroidKaigi 2026 「個人開発という実験場: Android エンジニアが手にする4つの自由」
slashnephy
0
230
Heart of Swift Concurrency
koher
0
230
AI Agent時代のリアーキテクチャ戦略と実践
hokaccha
9
3.9k
iOSDC Japan 2026 - Swiftで作って学ぼう!データベース自作入門
kaseken
2
100
iOS開発×AI駆動開発 〜最近使って便利だったスキルの話〜
nogu66
0
140
Vibes Containers 〜AIで変わるコンテナ設計と運用〜
tkikuc
3
530
初心者DevRelとして参加者だった私が、DevRel Talks!#2に登壇するまでにしてきたこと
sokohirai
0
360
高専キャリア LT 発表内容
crysta1221
6
5.6k
Featured
See All Featured
Why Your Marketing Sucks and What You Can Do About It - Sophie Logan
marketingsoph
0
410
Crafting Experiences
bethany
1
320
Build your cross-platform service in a week with App Engine
jlugia
234
19k
Efficient Content Optimization with Google Search Console & Apps Script
katarinadahlin
PRO
1
850
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
230
23k
StorybookのUI Testing Handbookを読んだ
zakiyama
31
6.9k
Side Projects
sachag
456
43k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
32
3k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
17k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
37
6.6k
SEO in 2025: How to Prepare for the Future of Search
ipullrank
3
3.8k
From π to Pie charts
rasagy
0
360
Transcript
Vue × Vuex ͷΞʔΩς Ϋνϟશʹཧղͨ͠
ࣗݾհ • ԕ౻ (entaku) • Twitter: @entaku19890818 • iOS/Android/Vue ΤϯδχΞ
• ܦྺ: ͳΜͪΌͬͯSE ->NWΤϯδχΞ[SIer] ->αʔόʔαΠυΤϯδχΞ[SIer](java/PHP..etc) ->iOS/Android ΞϓϦ։ൃ[ελʔτΞοϓ] Vue/Android…etc@CBCloudʹͳΓ·͢ <- NEW
ʢࢀরɿhttps://cb-cloud.com/ ʣ
ΞδΣϯμ • 0. ར༻ٕज़ • 1. Vue / Vuex ΞʔΩςΫνϟɹʙԿΛͲ͜ʹدͤΔ͔ʁʙ
• 2. σβΠϯ ʙσβΠφʔͱͷίϛϡχέʔγϣϯͱίϯϙʔ ωϯτͷ͚ํʁʙ • 3. ։ൃݴޠ ʙTypeScriptΛ͍͍ͨʙ
0.ར༻ٕज़
0.ར༻ٕज़
0.ར༻ٕज़ • Vue (ൃԻ / v j u ː /
ɺ view ͱಉ༷ʣϢʔβʔΠϯλʔϑΣΠεΛߏங͢ΔͨΊͷϓϩ άϨογϒϑϨʔϜϫʔΫͰ͢ɻଞͷҰຕ൘(ϞϊϦγοΫ: monolithic)ͳϑϨʔϜϫʔΫ ͱҟͳΓɺVue গͣͭ͠ద༻͍͚ͯ͠ΔΑ͏ʹઃܭ͞Ε͍ͯ·͢ɻத֩ͱͳΔϥΠϒϥ Ϧ view ͚ͩʹযΛ͍ͯͯ·͢ɻͦͷͨΊɺ͍࢝ΊΔͷɺଞͷϥΠϒϥϦط ଘͷϓϩδΣΫτʹ౷߹͢Δͷɺͱͯ؆୯Ͱ͢ɻ·ͨɺϞμϯͳπʔϧαϙʔτϥΠ ϒϥϦͱซ༻͢Δ͜ͱͰɺચ࿅͞ΕͨγϯάϧϖʔδΞϓϦέʔγϣϯͷ։ൃՄೳͰ͢ɻ ʢࢀরɿhttps://jp.vuejs.org/ ʣ
0.ར༻ٕज़ • NuxtɺϞμϯͳ web ΞϓϦέʔγϣϯΛ࡞͢Δ Vue.js ʹج͍ͮͨϓϩά ϨογϒϑϨʔϜϫʔΫͰ͢ɻVue.js ެࣜϥΠϒϥϦʢvueɺvue-router
vuexʣ͓Αͼڧྗͳ։ൃπʔϧʢwebpackɺBabel PostCSSʣʹج͍ͮͯ ͍·͢ɻ Nuxt ͷඪɺ༏Εͨ։ൃऀΤΫεϖϦΤϯεΛ೦಄ʹஔ͖ɺWeb ։ൃΛڧྗ͔ͭߴੑೳʹ͢Δ͜ͱͰ͢ɻ ʢࢀরɿhttps://ja.nuxtjs.org/ ʣ
0.ར༻ٕज़ • ElementUIɺVue 2.0ϕʔεͷUIίϯϙʔωϯτϥΠϒϥϦɻ • ͋Β͔͡ΊElementUIͰ༻ҙ͞ΕͨίϯϙʔωϯτΛ༨ʹ HTML/CSS/JSΛΧελϜ͢Δඞཁ͕ͳ͘ͳΔ ʢࢀরɿhttps://element.eleme.io/ ʣ
جຊߏ /utils /store /static /plugins /pages ./package.json ./nuxt.config.js /middleware /lib_sources
/layouts /components /organisms /molecules /atomsɹ /assets /api
Nuxt ॳظߏ BTTFUTσΟϨΫτϦʹ4UZMVT4"44ɺ*NBHFɺ'POUͷΑ͏ͳί ϯύΠϧ͞Ε͍ͯͳ͍ϑΝΠϧΛೖΕ·͢ɻ DPNQPOFOUTσΟϨΫτϦʹ7VFKTͷίϯϙʔωϯτϑΝΠϧΛೖ Ε·͢ɻ͜ΕΒͷίϯϙʔωϯτͰBTZOD%BUBGFUDIΛ͏͜ͱ Ͱ͖·ͤΜɻ MBZPVUTσΟϨΫτϦΞϓϦέʔγϣϯͷϨΠΞτΛؚΈ·͢ɻϨ ΠΞτϖʔδͷ֎؍Λมߋ͢ΔͨΊʹ༻͞Ε·͢ʢྫ͑αΠυ όʔͳͲʣɻ
NJEEMFXBSFσΟϨΫτϦʹΞϓϦέʔγϣϯͷϛυϧΣΞΛೖΕ ·͢ɻϛυϧΣΞΛͬͯɺϖʔδϖʔδάϧʔϓʢϨΠΞτʣΛ ϨϯμϦϯά͢ΔΑΓલʹ࣮ߦ͞ΕΔΧελϜؔΛఆٛͰ͖·͢ɻ QBHFTσΟϨΫτϦʹΞϓϦέʔγϣϯͷϏϡʔٴͼϧʔςΟϯάϑΝ ΠϧΛೖΕ·͢ɻ/VYUKTϑϨʔϜϫʔΫ͜ͷσΟϨΫτϦͷͯ͢ ͷWVFϑΝΠϧΛಡΈࠐΈɺΞϓϦέʔγϣϯͷϧʔλʔΛ࡞͠· TUBUJDσΟϨΫτϦαʔόͷϧʔτʹஔ͞ΕʢTUBUJD SPCPUTUYUIUUQMPDBMIPTUSPCPUTUYUͰΞΫηεՄೳͰ ͢ʣɺมߋ͞Εͳ͍Մೳੑͷߴ͍ϑΝΠϧؚ͕·Ε͍ͯ·͢ʢྫ͑ɺ TUPSFσΟϨΫτϦʹ7VFYετΞͷϑΝΠϧΛೖΕ·͢ɻ7VFYε τΞ/VYUKTʹଐ͍ͯ͠·͕͢ɺσϑΥϧτͰແޮʹͳ͍ͬͯ· ͢ɻ͜ͷσΟϨΫτϦʹJOEFYKTɹϑΝΠϧΛ࡞͢ΔͱετΞ͕༗ޮ /utils /store /static /plugins /pages ./package.json ./nuxt.config.js /middleware /lib_sources /layouts /components /organisms /molecules /atomsɹ /assets /api ʢࢀরɿhttps://ja.nuxtjs.org/guide/directory-structure ʣ
Nuxt ॳظߏ BTTFUTσΟϨΫτϦʹ4UZMVT4"44ɺ*NBHFɺ'POUͷΑ͏ͳί ϯύΠϧ͞Ε͍ͯͳ͍ϑΝΠϧΛೖΕ·͢ɻ DPNQPOFOUTσΟϨΫτϦʹ7VFKTͷίϯϙʔωϯτϑΝΠϧΛೖ Ε·͢ɻ͜ΕΒͷίϯϙʔωϯτͰBTZOD%BUBGFUDIΛ͏͜ͱ Ͱ͖·ͤΜɻ MBZPVUTσΟϨΫτϦΞϓϦέʔγϣϯͷϨΠΞτΛؚΈ·͢ɻϨ ΠΞτϖʔδͷ֎؍Λมߋ͢ΔͨΊʹ༻͞Ε·͢ʢྫ͑αΠυ όʔͳͲʣɻ
NJEEMFXBSFσΟϨΫτϦʹΞϓϦέʔγϣϯͷϛυϧΣΞΛೖΕ ·͢ɻϛυϧΣΞΛͬͯɺϖʔδϖʔδάϧʔϓʢϨΠΞτʣΛ ϨϯμϦϯά͢ΔΑΓલʹ࣮ߦ͞ΕΔΧελϜؔΛఆٛͰ͖·͢ɻ QBHFTσΟϨΫτϦʹΞϓϦέʔγϣϯͷϏϡʔٴͼϧʔςΟϯάϑΝ ΠϧΛೖΕ·͢ɻ/VYUKTϑϨʔϜϫʔΫ͜ͷσΟϨΫτϦͷͯ͢ ͷWVFϑΝΠϧΛಡΈࠐΈɺΞϓϦέʔγϣϯͷϧʔλʔΛ࡞͠· TUBUJDσΟϨΫτϦαʔόͷϧʔτʹஔ͞ΕʢTUBUJD SPCPUTUYUIUUQMPDBMIPTUSPCPUTUYUͰΞΫηεՄೳͰ ͢ʣɺมߋ͞Εͳ͍Մೳੑͷߴ͍ϑΝΠϧؚ͕·Ε͍ͯ·͢ʢྫ͑ɺ TUPSFσΟϨΫτϦʹ7VFYετΞͷϑΝΠϧΛೖΕ·͢ɻ7VFYε τΞ/VYUKTʹଐ͍ͯ͠·͕͢ɺσϑΥϧτͰແޮʹͳ͍ͬͯ· ͢ɻ͜ͷσΟϨΫτϦʹJOEFYKTɹϑΝΠϧΛ࡞͢ΔͱετΞ͕༗ޮ /utils /store /static /plugins /pages ./package.json ./nuxt.config.js /middleware /lib_sources /layouts /components /organisms /molecules /atomsɹ /assets /api /VYUͰ͍͍ͩͨἧ͏ʂʂ
ࠓճͨ͠ͷ BYJPTΛར༻ͨ͠"1*ͷॲཧ "UPNJD%FTJHOΛجʹͨ͠ίϯϙʔωϯτߏɻ 1BHFT͔Β͜ΕΒΛݺͼग़͢Α͏ʹͨ͠ ֎෦ϥΠϒϥϦͷಋೖʹ༻ͨ͠ ڞ௨Ͱར༻͢Δؔͷอઌ /utils /store /static /plugins
/pages ./package.json ./nuxt.config.js /middleware /lib_sources /layouts /components /organisms /molecules /atomsɹ /assets /api
ࠓճओʹ͢ൣғ QBHFTσΟϨΫτϦʹΞϓϦέʔγϣϯͷϏϡʔٴͼϧʔςΟϯάϑΝ ΠϧΛೖΕ·͢ɻ/VYUKTϑϨʔϜϫʔΫ͜ͷσΟϨΫτϦͷͯ͢ ͷWVFϑΝΠϧΛಡΈࠐΈɺΞϓϦέʔγϣϯͷϧʔλʔΛ࡞͠· TUPSFσΟϨΫτϦʹ7VFYετΞͷϑΝΠϧΛೖΕ·͢ɻ7VFYε τΞ/VYUKTʹଐ͍ͯ͠·͕͢ɺσϑΥϧτͰແޮʹͳ͍ͬͯ· ͢ɻ͜ͷσΟϨΫτϦʹJOEFYKTɹϑΝΠϧΛ࡞͢ΔͱετΞ͕༗ޮ /utils /store /static
/plugins /pages ./package.json ./nuxt.config.js /middleware /lib_sources /layouts /components /organisms /molecules /atomsɹ /assets /api DPNQPOFOUTσΟϨΫτϦʹ7VFKTͷίϯϙʔωϯτϑΝΠϧΛೖ Ε·͢ɻ͜ΕΒͷίϯϙʔωϯτͰBTZOD%BUBGFUDIΛ͏͜ͱ Ͱ͖·ͤΜɻ "UPNJD%FTJHOΛجʹͨ͠ίϯϙʔωϯτߏɻ 1BHFT͔Β͜ΕΒΛݺͼग़͢Α͏ʹͨ͠
1.Vue / Vuex ΞʔΩςΫ νϟɹʙԿΛͲ͜ʹدͤΔ͔ʁʙ
ࠓճओʹ͢ൣғΠϝʔδ ʢࢀরɿhttps://vuex.vuejs.org/ja/ ʣ
Πϝʔδ͕ શ͡Όͳ͍ؾ͕͢Δ ʢࢀরɿhttps://vuex.vuejs.org/ja/ ʣ
(FUUFS 1BHFT $POQP SOFOU ࠓճओʹ͢ൣғͷΠϝʔδ(վม) ʢࢀরɿhttps://vuex.vuejs.org/ja/ ʣ
(FUUFS 1BHFT $POQP SOFOU Pages ʢࢀরɿhttps://vuex.vuejs.org/ja/ ʣ
Pages <template> // HTMLΛॻ͘ॴ </template> <script> // JSΛॻ͘ॴ </script> <style
scoped lang=“scss"> // CSSΛॻ͘ॴ </style>
<template> <components></components > </template> <script> import Components from ‘@/components/organisms/Components' components:
{ Components } </script> Pages - ίϯϙʔωϯτͷݺͼग़͠-
Pages - ίϯϙʔωϯτͷݺͼग़͠- <template> <components></components > </template> <script> import Components
from `@/components/organisms/Components` components: { Components } </script> ݺͼग़͠ 7JFXͷඳը
Pages - vuexͷݺͼग़͠- <template> <components :data=”data” ></components > </template> <script>
import { mapGetters, mapActions} from 'vuex' computed: { ...mapGetters(`Store`, [‘data’]) }, async fetch({ store, params }) { store.dispatch(‘Store/getFirstData') }, methods: { ...mapActions(`Store`, [‘update’]), async getDriverOnMap() { await this.update() } } </script>
Pages - vuexͷݺͼग़͠- <template> <components :data=”data” ></components > </template> <script>
import { mapGetters, mapActions} from 'vuex' computed: { ...mapGetters(`Store`, [‘data’]) }, async fetch({ store, params }) { store.dispatch(‘Store/getFirstData') }, methods: { ...mapActions(`Store`, [‘update’]), async getDriverOnMap() { await this.update() } } </script> (FUUFSͰݺͼग़͠ ͨ༰ͷදࣔ (FUUFSͷݺͼग़͠ "DUJPOͷݺͼग़͠ "DUJPOͷ࣮ߦ ॳظදࣔͳͲ ͷݺͼग़͠
(FUUFS 1BHFT $POQP SOFOU Vuex ʢࢀরɿhttps://vuex.vuejs.org/ja/ ʣ
Vuex - state- export const state = () => ({
array: [], firstName: ``, lastName: ``, }) • σʔλͷอઌ
Vuex - mutations - export const mutations = { [types.SET_ARRAY](state,
array) { state.array = array }, [types.SET_FIRST_NAME](state, firstName) { state.firstName = firstName }, [types.SET_LAST_NAME](state, lastName) { state.lastName = lastName } } • σʔλͷมߋ
export const getters = { fullName: state => { return
state.firstName + state.lastName }, array: state => { return state.array } } Vuex - getters - • σʔλͷऔಘ
export const actions = { async fetchUser({ commit }) {
const user = await fetchUser() commit(types.SET_FIRST_NAME, user.firstName) commit(types.SET_LAST_NAME, user.lastName) } } Vuex - actions - • σʔλͷߋ৽ॲཧ
ࣦഊͨ͜͠ͱ
ࣦഊͨ͜͠ͱ • StateΛࢀর͍ͯ͠Δ.. • ActionΛ௨͞ͳ͍MutationͷॲཧΛ͔͍ͯ͠·ͬͨ..
<template> <div> {{firstName}} </div> </template> <script> export default { computed:
{ ...mapState(`store`, ['firstName']) }, methods: { update() { this.$store.commit(‘store/' + types.SET_FIRST_NAME) } } } </script> <style scoped lang=“scss"> // CSSΛॻ͘ॴ </style> ࣦഊͨ͜͠ͱ • StateΛࢀর͍ͯ͠Δ.. • ActionΛ௨͞ͳ͍MutationͷॲཧΛ͔͍ͯ͠·ͬͨ..
ͳͥState/MutationΛΑͿ ͷ͕·͍ͣͷ͔ʁ
ͳͥState/MutationΛΑͿ ͷ͕·͍ͣͷ͔ʁ • StateΛࢀর͢ΔͱɺVuexʹอଘ͞Ε͍ͯΔσʔλΛԿհ ͣ͞ʹݟΔ͜ͱʹͳΔɻGetterͳͲͰදࣔ༰Λมߋͯ͠ࢀর ͍ͯ͠Δ߹͕͋ΔͨΊɺใͷҰҙੑ͕อͯͳ͘ͳΔ͔Β • MutationΛݺͿ͜ͱͰvueϑΝΠϧ͔ΒɺStateͷ༰Λॻ ͖͑Δ͜ͱ͕Ͱ͖Δɻ͜ΕϩδοΫΛvueϑΝΠϧʹࡏ͠ ͯ͠·͏ͷͰɺߋ৽ॲཧActionsʹدͤΔɻ
(FUUFS 1BHFT $POQP SOFOU "
1.Vue / Vuex ΞʔΩςΫ νϟɹʙԿΛͲ͜ʹدͤΔ͔ʁʙ • ࢀরॲཧgettersʹΑͤΔ • ߋ৽ॲཧActionsʹدͤΔ •
vue͔ΒgettersͱActionsͷΈΛࢀর͢Δ • stategetters͔Βࢀর͢Δ • MutationActions͔Βߋ৽͢Δ
2.σβΠϯ ʙσβΠφʔͱͷίϛϡχ έʔγϣϯͱίϯϙʔωϯτͷ͚ํʁʙ
Atomic DesignΛ࠾༻ʂ
Atomic Designͱʁ • Atomic Design ͱ ɺBrad Frostࢯ͕ఏএͨ͠UIઃܭʹ͓͍ͯ ίϯϙʔωϯτΛํ๏/ࢥͰ͢ɻ •
ϑϩϯτΤϯυͷઃܭࢥͷΑ͏ʹޠΒΕ͍ͯΔࣄ͋Γ·͢ ͕ɺ͋͘·ͰσβΠϯͷઃܭʹ͍ͭͯͷͷͰ͢ɻ ʢࢀরɿhttp://atomicdesign.bradfrost.com/ ʣ
Atomic Designͱʁ ʢࢀরɿhttp://atomicdesign.bradfrost.com/ ʣ
None
Atoms <template> <el-input class="Input" v-model="value" :type="inputType" :placeholder="placeholder" :disabled="isDisabled" @blur="$emit('blur')" />
</template> <script> props: { value: { type: String, default: '' } } </script> <style scoped lang=“scss"> // CSSΛॻ͘ॴ </style> • element-uiίϯϙʔωϯτͷϥο ύʔ͔ͦͷͷΛ͍ΕΔ
Molecules <template> <div class=”Form”> <Label /> <Input /> </div> </template>
<script> import Input from ‘@/components/atoms/Input’ import Label from ‘@/components/atoms/Label’ </script> <style scoped lang=“scss"> // CSSΛॻ͘ॴ </style> • 1ͭҎ্ͷAtoms͕ར༻͞Ε͍ͯΔ
Organisms <template> <div class=”Basic”> <Form /> <Form /> <Button />
</div> </template> <script> import Form from ‘@/components/molecules/Form’ import Button from ‘@/components/molecules/Button’ export default { } </script> <style scoped lang=“scss"> // CSSΛॻ͘ॴ </style>
Templates <template> <div class=”InputPage”> <Basic /> <Custom /> </div> </template>
<script> import Basic from ‘@/components/organisms/Basic’ import Custom from ‘@/components/organisms/Custom’ </script> <style scoped lang=“scss"> // CSSΛॻ͘ॴ </style>
Pages <template> <div class=”InputPage”> <InputPage /> </div> </template> <script> import
InputPage from ‘@/components/templates/InputPage’ // StoreͷΞΫηεॲཧPages͚ͩ…! </script> <style scoped lang=“scss”></style>
Atomic DesignͰࣦഊͨ͜͠ͱ
Atomic DesignͰࣦഊͨ͜͠ͱ • elementUI४ڌʹܾΊͨͷʹ͔ͳΓΧελϜͰ࡞ͬͯ͠·ͬͨ UIɻ • TemplatesΛೖΕͣʹ։ൃ͍ͯͨ͠… • ֊͕ਂ͘ͳΓແݶemitࠈ..
ΧελϜͰ࡞ͬͯ͠·ͬͨUIɻ • ཁ݅ΛܾΊΔࡍʹσβΠϯ͕มΘͬͯ͠·͏ • σβΠϯγεςϜ͕ߏஙͰ͖͍ͯͳ͔ͬͨ
ʢࢀরɿhttps://note.mu/smartcamp_design/n/n4e4717e9d8d0 ʣ Atomic Design ͱ Figma ͷΈ߹ΘͤͰσβΠϯ͕ศརʹͳΔʛσβΠϯγεςϜͷ࡞Γํ ΧελϜͰ࡞ͬͯ͠·ͬͨUIɻ
TemplatesΛೖΕͣʹ։ൃ͍ͯ͠ ͨ… ❌ ංେԽɹ
TemplatesΛೖΕͣʹ։ൃ͍ͯ͠ ͨ… ❌
ແݶemitࠈ.. DMJDL&WFOU DMJDL&WFOU DMJDL&WFOU DMJDL&WFOU DMJDL&WFOU emit emit emit emit
3. ։ൃݴޠ ʙTypeScriptΛ͍ͨ ͍ʙ (్த)
੩తܕ͚Ͱ։ൃ͍ͨ͠ʂʂʂʂ
ͦ͏SwiftͷΑ͏ʹ..
Swiftͷߏମͷѻ͍ struct Team: Decodable { let id:Int let name:String let
shortName:String let crestUrl:URL let website:URL let venue:String } —— let team:Team = Team()
ͦ͜ͰTypeScriptͰ͢Α
Vuex - types - export interface RootState { version: string;
} export interface TeamsState { teams: Team[] } export interface Team { ɹ id: number; name:string; area: Area; crestUrl: string; } export interface Area { id: string; name: string; } • σʔλͷఆٛ
Vuex - index/state- const state: TeamsState = { teams: [],
}; export const todos: Module<TeamsState, RootState> = { namespaced: true, state, getters, actions, mutations }; • σʔλͷอઌ
Vuex - mutations - export const mutations: MutationTree<TeamsState> = {
teamsLoaded(state, teams: Team[]) { state.teams = teams }, teamsError(state) { state.teams = [] } } • σʔλͷมߋ
const getters: GetterTree<TeamsState, RootState> = { teams: (state: TeamsState) =>
{ return state }, } Vuex - getters - • σʔλͷऔಘ
const actions: ActionTree<TeamsState, RootState>= { fetch: async ({ commit })
=> { try { const res = await axios.get('https://api.football-data.org/v2/competitions/PL/teams/', { headers: { 'X-Auth-Token': ‘XXXX' } }) const teams: Team[] = res.data.teams commit('teamsLoaded', teams) } catch (error) { // commit('teamsError') } }, }; Vuex - actions - • σʔλͷߋ৽ॲཧ
Pages - vuexͷݺͼग़͠- <template> <div> {{ message }} <div v-for="team
in teams.teams" :key='team.id'> {{team.name}} </div> </div> </template> <script lang="ts"> import { Vue } from 'vue-property-decorator'; import { mapGetters, mapActions, mapState, mapMutations } from 'vuex' export default Vue.extend({ data () { const message: string = 'This is a message' return { message } }, computed: { ...mapGetters(`Team`, ['teams']) }, async fetch ({ store, params }) { await store.dispatch('Team/fetch') } }) ·ͩͰ͖ͯͳ͍Α
GitHub https://github.com/entaku19890818/football-nuxt
·ͱΊ • ར༻ٕज़ • Nuxtʹ΄΅͕ͯ͋͢Δ • Vue / Vuex ΞʔΩςΫνϟ
• ࢀরॲཧgettersʹΑͤΔ • ߋ৽ॲཧActionsʹدͤΔ • σβΠϯ • UIϑϨʔϜϫʔΫΛҙࣝͨ͠σβΠφʔͱͷίϛϡχέʔγϣϯ • σβΠϯγεςϜͭ͘Δ • ։ൃݴޠ • TypeScriptͰ৺ཧత҆શੑͷߴ͍։ൃΛ…
͝੩ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠ʂ