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
生成AI導入の「期待外れ」を乗り越える ー 開発フロー改革が目指す、真の組織変革
starfish719
0
5.1k
AI Engineeringは、AIプロダクトだけのものか? 〜AIがソフトウェアを作る時代の新しい当たり前〜 / No AI in your product. AI Engineering in your development.
rkaga
5
510
そこに3びきプロダクトがいるじゃろう——生成AI時代における“価値が届かない理由”の構造
kosuket
0
560
書籍「プロフェッショナルAI駆動開発」紹介スライド
juntaromatsumoto
0
280
わからない話を追いかけたら、プログラミング言語を作る側にいた
ydah
3
540
ここ半年くらいでAIに作らせたR用ツール
eitsupi
0
400
属人化した知識を、 AIが辿れる地図にする
pkshadeck
PRO
1
200
Gmail/Google DriveをトリガーにAIエージェントを動かそう! / Run AI agents with Gmail/Google Drive as triggers!
har1101
2
420
承認済みなのに差戻しできてしまうバグ、型で潰せます
shinchit
0
100
改善しないと、タスクが回らない。 “てんこ盛りポジション” を引き継いだ情シスの、入社3ヶ月の業務改善録
krm963
0
280
Dockerfile CMD for Node.js
grazie1999
0
110
170k Jobs a Day on GKE: Scaling Mercari's CI Platform - and What's Next for AI-Native Development
junyaokabe
0
120
Featured
See All Featured
Why You Should Never Use an ORM
jnunemaker
PRO
61
10k
How to make the Groovebox
asonas
2
2.3k
Deep Space Network (abreviated)
tonyrice
0
270
How to train your dragon (web standard)
notwaldorf
97
6.8k
The Hidden Cost of Media on the Web [PixelPalooza 2025]
tammyeverts
2
470
Chasing Engaging Ingredients in Design
codingconduct
0
280
Why Mistakes Are the Best Teachers: Turning Failure into a Pathway for Growth
auna
0
210
The Impact of AI in SEO - AI Overviews June 2024 Edition
aleyda
6
1.2k
Designing Experiences People Love
moore
143
24k
Measuring Dark Social's Impact On Conversion and Attribution
stephenakadiri
2
260
jQuery: Nuts, Bolts and Bling
dougneiner
66
8.5k
Exploring the relationship between traditional SERPs and Gen AI search
raygrieselhuber
PRO
2
4.2k
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はリアクティブデータなの で、参照しているだけで値の変 更に伴う画面表示の変更を自 動で行っていくる