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
Foundation Models frameworkで画像分析
ryodeveloper
1
140
今さら聞けない .NET CLI
htkym
0
130
PostgreSQL 18で考えるUUID主キー
kazuhiro1982
0
400
型も通る、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
440
数百円から始めるRuby電子工作
tarosay
0
110
はてなアカウント基盤 State of the Union
cockscomb
1
1.3k
才能?センス?知らん、 続けたもん勝ちだ。-- 結婚・出産・癌を越えてなお、私がプロダクトを創り続ける理由
16bitidol
2
910
任せる範囲はこう広がった / How the Scope of AI Delegation Has Expanded
nrslib
1
280
AWS CDK を「作」ってみた 〜フルスクラッチで見えた CDK の裏側〜 / aws-cdk-from-scratch
gotok365
3
2.5k
信頼性について考えてみる(SRE NEXT 2026 miniLT)
hayama17
0
210
AIが無かった頃の素敵な出会いの話
codmoninc
1
230
使用 Meilisearch 建立新聞搜尋工具
johnroyer
0
170
Featured
See All Featured
Done Done
chrislema
186
16k
Navigating the moral maze — ethical principles for Al-driven product design
skipperchong
2
420
KATA
mclloyd
PRO
35
15k
Abbi's Birthday
coloredviolet
3
8.8k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3.5k
Six Lessons from altMBA
skipperchong
29
4.3k
DBのスキルで生き残る技術 - AI時代におけるテーブル設計の勘所
soudai
PRO
67
56k
Mobile First: as difficult as doing things right
swwweet
225
10k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.8k
SERP Conf. Vienna - Web Accessibility: Optimizing for Inclusivity and SEO
sarafernandez
2
1.5k
Building an army of robots
kneath
306
46k
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
3
1k
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はリアクティブデータなの で、参照しているだけで値の変 更に伴う画面表示の変更を自 動で行っていくる