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
Nuxt.js_Vue.js_のVuexの動かしかたをまとめてみたよ.pdf
Search
omiend
January 22, 2019
Programming
120
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Nuxt.js_Vue.js_のVuexの動かしかたをまとめてみたよ.pdf
omiend
January 22, 2019
More Decks by omiend
See All by omiend
スクラッチ組織活用術 Salesforce Developers Meetup #24
omiend
0
1.4k
Nuxt.jsのComponent分割単位と,SSRをする上で気をつけること
omiend
1
810
20181208_好きだけじゃツライScala.js_共有版_.pdf
omiend
0
130
20181110 Scala関西Summit 懇親会LT「Scalaのかわいいところ」
omiend
0
590
Other Decks in Programming
See All in Programming
freeeにおけるEvalsの実践例の紹介
freee
PRO
0
120
Android CLI
fornewid
0
220
<title><a id="</title>君はこのHTMLをパースできるか"></a></title> #雑LT_study
pizzacat83
0
150
型も通る、synthも通る、それでも危ない 〜AIのCDKの権限とコストを機械で検証する〜 / It Passes Type Checks, It Passes Synth Checks, but It’s Still Risky — Automatically Verifying Permissions and Costs in AI’s CDK —
seike460
PRO
1
560
Terraform標準の組織で AWS CDKをどう使うか
mu7889yoon
1
520
Laravelで学ぶ Webアプリケーションチューニング入門/web_application_tuning_101
hanhan1978
4
1.9k
Japan Community Day at Kubecon + CloudNativeCon Japan 2026: Learning Container Privilege Control by Building My Own Low-Level Container Runtime
ternbusty
1
160
Go言語とトイモデルで学ぶTransformerの気持ち / fukuokago23-transformer
monochromegane
0
180
Foundation Models frameworkで画像分析
ryodeveloper
1
620
「寝てても仕事が進む」Claude Codeで組む第二の脳
tomoyafujita2016
0
340
AIを紡ぐPMのお話
swdtkuy
0
110
これって Effect でできたのでは? / TSKaigi Mashup Kansai #2
susisu
0
240
Featured
See All Featured
16th Malabo Montpellier Forum Presentation
akademiya2063
PRO
0
350
[RailsConf 2023] Rails as a piece of cake
palkan
59
6.9k
Become a Pro
speakerdeck
PRO
31
6.2k
The Power of CSS Pseudo Elements
geoffreycrofte
82
6.5k
GraphQLの誤解/rethinking-graphql
sonatard
75
12k
Learning to Love Humans: Emotional Interface Design
aarron
275
41k
Balancing Empowerment & Direction
lara
6
1.2k
Principles of Awesome APIs and How to Build Them.
keavy
128
18k
Practical Orchestrator
shlominoach
191
12k
A brief & incomplete history of UX Design for the World Wide Web: 1989–2019
jct
2
470
The AI Search Optimization Roadmap by Aleyda Solis
aleyda
1
6.1k
Automating Front-end Workflow
addyosmani
1369
210k
Transcript
Nuxt.js(Vue.js)のVuexの動かしかたをまとめてみたよ。 @omiend
Store Page export const mutations = { increment_mutation (state, payload)
{ state.counter++ state.click_date = payload.click_date } } export const actions = { increment_action ({ commit }, payload) { commit('increment_mutation', { click_date: payload.click_date }) } } export const state = () => ({ counter: 0, click_date: "" }) computed: { counter() { return this.$store.state.counter }, click_date() { return this.$store.state.click_date } } methods: { increment() { this.$store.dispatch('increment_action', { click_date: new Date }) } } <template> <div> <p>{{counter}}</p> <p>{{click_date}}</p> <button @click="increment()">カウントアップ </button> </div> </template>
Store Page export const mutations = { increment_mutation (state, payload)
{ state.counter++ state.click_date = payload.click_date } } export const actions = { increment_action ({ commit }, payload) { commit('increment_mutation', { click_date: payload.click_date }) } } export const state = () => ({ counter: 0, click_date: "" }) computed: { counter() { return this.$store.state.counter }, click_date() { return this.$store.state.click_date } } methods: { increment() { this.$store.dispatch('increment_action', { click_date: new Date }) } } <template> <div> <p>{{counter}}</p> <p>{{click_date}}</p> <button @click="increment()">カウントアップ </button> </div> </template> クリックすると
Store Page export const mutations = { increment_mutation (state, payload)
{ state.counter++ state.click_date = payload.click_date } } export const actions = { increment_action ({ commit }, payload) { commit('increment_mutation', { click_date: payload.click_date }) } } export const state = () => ({ counter: 0, click_date: "" }) computed: { counter() { return this.$store.state.counter }, click_date() { return this.$store.state.click_date } } methods: { increment() { this.$store.dispatch('increment_action', { click_date: new Date }) } } <template> <div> <p>{{counter}}</p> <p>{{click_date}}</p> <button @click="increment()">カウントアップ </button> </div> </template> methodsに定義されたメソッド が実行され
Store Page export const mutations = { increment_mutation (state, payload)
{ state.counter++ state.click_date = payload.click_date } } export const actions = { increment_action ({ commit }, payload) { commit('increment_mutation', { click_date: payload.click_date }) } } export const state = () => ({ counter: 0, click_date: "" }) computed: { counter() { return this.$store.state.counter }, click_date() { return this.$store.state.click_date } } methods: { increment() { this.$store.dispatch('increment_action', { click_date: new Date }) } } <template> <div> <p>{{counter}}</p> <p>{{click_date}}</p> <button @click="increment()">カウントアップ </button> </div> </template> メソッドの中ではactionsの処 理をdispatchすることで呼び せる ここでmutationsの処理を commitすることで呼び出す もできる
Store Page export const mutations = { increment_mutation (state, payload)
{ state.counter++ state.click_date = payload.click_date } } export const actions = { increment_action ({ commit }, payload) { commit('increment_mutation', { click_date: payload.click_date }) } } export const state = () => ({ counter: 0, click_date: "" }) computed: { counter() { return this.$store.state.counter }, click_date() { return this.$store.state.click_date } } methods: { increment() { this.$store.dispatch('increment_action', { click_date: new Date }) } } <template> <div> <p>{{counter}}</p> <p>{{click_date}}</p> <button @click="increment()">カウントアップ </button> </div> </template> actionsに定義された処理では mutationsの処理をcommitす ることで呼び出せる
Store Page export const mutations = { increment_mutation (state, payload)
{ state.counter++ state.click_date = payload.click_date } } export const actions = { increment_action ({ commit }, payload) { commit('increment_mutation', { click_date: payload.click_date }) } } export const state = () => ({ counter: 0, click_date: "" }) computed: { counter() { return this.$store.state.counter }, click_date() { return this.$store.state.click_date } } methods: { increment() { this.$store.dispatch('increment_action', { click_date: new Date }) } } <template> <div> <p>{{counter}}</p> <p>{{click_date}}</p> <button @click="increment()">カウントアップ </button> </div> </template> mutationsの中では、唯一 stateの状態を変更することが できる
Store Page export const mutations = { increment_mutation (state, payload)
{ state.counter++ state.click_date = payload.click_date } } export const actions = { increment_action ({ commit }, payload) { commit('increment_mutation', { click_date: payload.click_date }) } } export const state = () => ({ counter: 0, click_date: "" }) computed: { counter() { return this.$store.state.counter }, click_date() { return this.$store.state.click_date } } methods: { increment() { this.$store.dispatch('increment_action', { click_date: new Date }) } } <template> <div> <p>{{counter}}</p> <p>{{click_date}}</p> <button @click="increment()">カウントアップ </button> </div> </template> $store.stateでstateの状態 を参照することができる storeはリアクティブデータなの で、参照しているだけで値の変 更に伴う画面表示の変更を自 動で行っていくる