<p>ํ์ฌ ๋ ์ง : {{now}}</p>
computed : {
now(){
return new Datae()
}
}
computed : {
name(){
return this.$store.state.name
}
}
์คํฌ๋ฆฝํธ ํ๊ทธ ์์์ store์ด๋ค.
โ๏ธ๋จ์ ) ๊บผ๋ผ state๊ฐ 100๊ฐ ์์ผ๋ฉด computed๋ ๋ณต์กํด์ง๋ค. ๊ทธ๋ ๊ธฐ ๋๋ฌธ์ mapState๋ฅผ ์ด์ฉํ๋ฉด ๋๋ค.
...mapState
๋ฅผ ์ฌ์ฉํ๋ฉด ๋๋ค.import {mapState} from 'vuex'
computed : {
...mapState(['state์ด๋ฆ1','state์ด๋ฆ2'])
}
์๋ช ๊ฐ๋ฅ
import {mapState} from 'vuex'
computed : {
...mapState({ ์๋ช
: 'state์ด๋ฆ1' })
}
import {mapState, mapMutations} from 'vuex'
computed : {
...mapState(['state์ด๋ฆ1', 'state์ด๋ฆ2']),
...mapMutaions(['์ข์์', 'setMore'])
}
$store.commit('์ข์์')
๊ฐ ์๋๋ผ ์์ mapMutations์ ์ ์ํด ๋์ผ๋ฉด ์ข์์()
๋ก ์ฌ์ฉ๊ฐ๋ฅํ๋ค.
//App.vue
import { mapActions } from 'vuex'
computed : {
...mapActions(['delayClickBtn'])
}
//store.js
actions:{
delayClickBtn(context){
setTimeout(() => context.commit('clickBtn'),2000);
}
}