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
200
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
140
TCAでiOS開発を_学ぶ3つの利点.pdf
entaku
4
280
Other Decks in Programming
See All in Programming
Go × SIMDで高速化するベクトル検索 ~ルーフラインモデルでSIMDが効く境界を探れ! ~
po3rin
1
3.9k
Streamlitで実現する自然言語データアプリ開発
ayumu_yamaguchi
1
320
WebRTC映像をAirPlayに対応させる挑戦.pdf
monolithic_adam
0
310
海上で動くGoサーバー: goroutineとchannelでさばく航行データストリーム
atsuki_seo
0
950
SREの越境 / SRE Collaboration
y0hgi
2
280
一人だけ、Kiroが静止する日
hideg
0
130
IBM Bob Dojo #1 仕様駆動開発入門
oniak3ibm
PRO
0
270
Snowflakeで業務アプリを作ろう。 Snowflakeのアプリ機能解説&実践ガイド
ayumu_yamaguchi
2
300
MVNOの申込からeSIM開通までをiOSアプリでつなぐ- 本人確認・MNP・通信事業者基盤をまたぐ実装
satotakeshi
0
480
技術的負債を組織課題として解く-増えすぎたマイクロサービスとの戦い-
reimaru
1
2.4k
Building an Out-of-Order CPU
latte72
1
800
wkhtmltopdfの次どうするか問題2026
willnet
2
1.8k
Featured
See All Featured
GitHub's CSS Performance
jonrohan
1033
470k
Design in an AI World
tapps
1
330
Prompt Engineering for Job Search
mfonobong
0
460
The Pragmatic Product Professional
lauravandoore
37
7.5k
SEO Brein meetup: CTRL+C is not how to scale international SEO
lindahogenes
2
2.9k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
37
6.6k
Google's AI Overviews - The New Search
badams
0
1.6k
A Soul's Torment
seathinner
8
3.6k
Imperfection Machines: The Place of Print at Facebook
scottboms
270
14k
From Legacy to Launchpad: Building Startup-Ready Communities
dugsong
0
340
Navigating Algorithm Shifts & AI Overviews - #SMXNext
aleyda
1
1.6k
For a Future-Friendly Web
brad_frost
183
10k
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Ͱ৺ཧత҆શੑͷߴ͍։ൃΛ…
͝੩ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠ʂ