vuex ๋
vue js ๋ฅผ ์ํ ์ํ ๊ด๋ฆฌ ํจํด+๋ผ์ด๋ธ๋ฌ๋ฆฌ ์ด๋ค.
์ํ๋ ๋ฐ์ดํฐ(๋ฐ์์ฑ๋ฐ์ดํฐ) ์ด๋ค.
- State
Vue ์ data
- Getters
Vue ์ computed
- Mutations
์์ ๊ถํ์ด ์๋ method
- Actions
method
- Modules
import {createStore} from 'vuex'
export default createStore ({
// data
state() {
return {
count: 0
}
},
// ๊ณ์ฐ๋ data === computed
getters:{
double(state){
return state.count * 2
}
},
// ์์ ๊ถํ ๋ฉ์๋
//์์ ๊ถํ์ด ์๋ mutations์ ์ง์ ๋ด๋ณด๋ด์ ์ฐ๋ ๊ฒฝ์ฐ๋ ํผํ๋๊ฒ ์ข์
//์์ ๊ถํ์ด ๊ฑฐ์ ์ ๋ถ
//state์๋ง ์ ๊ทผํจ
mutations: {
increase(state){
state.count += 1
}
},
// ์ธ๋ถ์์ ์ธ๋ ์ก์
์๊ป, mutstions ๋ ๊ฐ๊ธ์ ๋ด๋ถ์์
// state, getters, mutations, actions ์ ๋ชจ๋ ์ ๊ทผ
//context
actions: {
// increase(context){
increase({commit}){
//mutations ์ ํธ์ถํ๋ comiit, actions ๋ฅผ ํธ์ถํ๋ dispatch
// ์ฌ์ฉ๊ถํ์ ๋ณต์กํจ์ ํด๊ฒฐํ ใ
ฃใ
์ดํด์
// const (state, getters, commit , dispatch) = context
// const {commit }= context
commit('increase')
}
}
})
์ถ์ฒ ํจ์คํธ์บ ํผ์ค ํํ ํฌ FE ๊ณผ์ ๋ฐ์์ ๊ฐ์ฌ๋
๋ฐ์ํ
'๐ TIL' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[220626] (0) | 2022.06.26 |
---|---|
[220526] vue payload (0) | 2022.05.27 |
[220519]component/props /emits (1) | 2022.05.20 |
[220516] data / methods/ computed/ watch (0) | 2022.05.16 |
[220506]๐ข callstack / DOM api (0) | 2022.05.06 |