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
120
20181110 Scala関西Summit 懇親会LT「Scalaのかわいいところ」
omiend
0
590
Other Decks in Programming
See All in Programming
エンジニア向け会社紹介/Findy Company Profile
findyinc
6
350k
肥大化するレガシーコードに立ち向かうためのインターフェース分離と依存の逆転 / JJUG CCC 2026 Spring
hirokunimaeta
0
580
AIとASP.NET Coreで雑Webアプリを作った話
mayuki
0
670
PHPで使える日時の表現と、その知り方 #frontend_phpcon_do
o0h
PRO
0
260
過去最大のMCPアップデート! 2026-07-28 RC版の謎に迫る
licux
6
370
「AIで開発し、AIを届ける」をEvalでつなぐ 〜AIネイティブに始めるプロダクト開発の実践〜 / Connecting "Develop with AI, deliver AI" with Eval
rkaga
4
5.3k
A2UI という光を覗いてみる
satohjohn
1
140
並列実装の現場、2ヶ月間実務でAIを使い倒したAIもPCも私も限界が近い
ming_ayami
0
130
Semantic Version 単位で戦略を柔軟に変えて、パッケージアップデートを自動化する
daitasu
1
270
トークンをケチるな、設計しろ:GitHub Copilotを賢く使うコンテキスト戦略
ochtum
0
110
脅威をエンジニアリングの糧にして――現場編 / Turning Threats into Engineering Fuel — Field Edition
nrslib
0
290
JJUG CCC 2026 Spring: JSpecify で実現する Kotlin フレンドリーな Java API 設計
ternbusty
1
180
Featured
See All Featured
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
17k
Agile that works and the tools we love
rasmusluckow
331
21k
Leveraging Curiosity to Care for An Aging Population
cassininazir
1
270
What Being in a Rock Band Can Teach Us About Real World SEO
427marketing
0
260
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
254
22k
4 Signs Your Business is Dying
shpigford
187
22k
Bootstrapping a Software Product
garrettdimon
PRO
307
120k
16th Malabo Montpellier Forum Presentation
akademiya2063
PRO
0
150
Jess Joyce - The Pitfalls of Following Frameworks
techseoconnect
PRO
1
170
Information Architects: The Missing Link in Design Systems
soysaucechin
0
980
Discover your Explorer Soul
emna__ayadi
2
1.1k
Highjacked: Video Game Concept Design
rkendrick25
PRO
1
400
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はリアクティブデータなの で、参照しているだけで値の変 更に伴う画面表示の変更を自 動で行っていくる