|
| 1 | +# API λ νΌλ°μ€ |
| 2 | + |
| 3 | +### Vuex.Store |
| 4 | + |
| 5 | +``` js |
| 6 | +import Vuex from 'vuex' |
| 7 | + |
| 8 | +const store = new Vuex.Store({ ...options }) |
| 9 | +``` |
| 10 | + |
| 11 | +### Vuex.Store μμ±μ μ΅μ
|
| 12 | + |
| 13 | +- **state** |
| 14 | + |
| 15 | + - μλ£ν: `Object` |
| 16 | + |
| 17 | + Vuex μ μ₯μμ λ£¨νΈ μν κ°μ²΄ μ
λλ€. |
| 18 | + |
| 19 | + [μμΈ](state.md) |
| 20 | + |
| 21 | +- **mutations** |
| 22 | + |
| 23 | + - μλ£ν: `{ [type: string]: Function }` |
| 24 | + |
| 25 | + μ μ₯μμ λ³μ΄λ₯Ό λ±λ‘νμμμ€. νΈλ€λ¬ ν¨μλ νμ 첫 λ²μ§Έ μ λ¬μΈμλ‘ `state`λ₯Ό λ°μ΅λλ€ (λͺ¨λμ μ μ λ κ²½μ° λͺ¨λ λ‘컬 μνκ°λ©λλ€). λ λ²μ§Έ `payload` μ λ¬μΈμκ° μμΌλ©΄ μ²λ¦¬ν©λλ€. |
| 26 | + |
| 27 | + [μμΈ](mutations.md) |
| 28 | + |
| 29 | +- **actions** |
| 30 | + |
| 31 | + - μλ£ν: `{ [type: string]: Function }` |
| 32 | + |
| 33 | + μ μ₯μμ μ‘μ
μ λ±λ‘νμμμ€. νΈλ€λ¬ ν¨μλ λ€μ μμ±μ λ
ΈμΆνλ `context` κ°μ²΄λ₯Όλ°μ΅λλ€. |
| 34 | + |
| 35 | + ``` js |
| 36 | + { |
| 37 | + state, // store.stateμ κ°μ΅λλ€. λλ λͺ¨λμ μλ κ²½μ° λ‘컬 μν |
| 38 | + rootState, // store.stateμ κ°μ΅λλ€. λͺ¨λ μμλ§ μ‘΄μ¬ν©λλ€ |
| 39 | + commit, // store.commitμ κ°μ΅λλ€. |
| 40 | + dispatch, // store.dispatchμ κ°μ΅λλ€. |
| 41 | + getters // store.gettersμ κ°μ΅λλ€. |
| 42 | + } |
| 43 | + ``` |
| 44 | + |
| 45 | + [μμΈ](actions.md) |
| 46 | + |
| 47 | +- **getters** |
| 48 | + |
| 49 | + - μλ£ν: `{ [key: string]: Function }` |
| 50 | + |
| 51 | + μ μ₯μμ getterλ₯Ό λ±λ‘νμμμ€. getter ν¨μλ λ€μ μ λ¬μΈμλ₯Ό λ°μ΅λλ€. |
| 52 | + |
| 53 | + ``` |
| 54 | + state, // λͺ¨λμ μ μ λ κ²½μ° λͺ¨λ λ‘컬 μνκ°λ©λλ€. |
| 55 | + getters, // store.gettersμ κ°μ΅λλ€. |
| 56 | + rootState // store.stateμ κ°μ΅λλ€. |
| 57 | + ``` |
| 58 | + |
| 59 | + λ±λ‘λ getterλ `store.getters`μ λ
ΈμΆλ©λλ€. |
| 60 | + |
| 61 | + [μμΈ](getters.md) |
| 62 | + |
| 63 | +- **modules** |
| 64 | + |
| 65 | + - μλ£ν: `Object` |
| 66 | + |
| 67 | + μ μ₯μμ λ³ν©λ νμ λͺ¨λμ ν¬ν¨νλ κ°μ²΄ μ
λλ€. |
| 68 | + |
| 69 | + ``` js |
| 70 | + { |
| 71 | + key: { |
| 72 | + state, |
| 73 | + mutations, |
| 74 | + actions?, |
| 75 | + getters?, |
| 76 | + modules? |
| 77 | + }, |
| 78 | + ... |
| 79 | + } |
| 80 | + ``` |
| 81 | + |
| 82 | + κ° λͺ¨λμ λ£¨νΈ μ΅μ
κ³Ό λΉμ·ν `state` μ `mutations` λ₯Ό ν¬ν¨ ν μ μμ΅λλ€. λͺ¨λμ μνλ λͺ¨λμ ν€λ₯Ό μ¬μ©νμ¬ μ μ₯μμ λ£¨νΈ μνμ μ°κ²°λ©λλ€. λͺ¨λμ λ³μ΄μ getterλ λͺ¨λμ λ‘컬 μνλ₯Ό λ£¨νΈ μν λμ 첫 λ²μ§Έ μ λ¬μΈμλ‘ λ°μΌλ©° λͺ¨λ μ‘μ
μ `context.state`λ λ‘컬 μνλ₯Ό κ°λ¦¬ ν΅λλ€. |
| 83 | + |
| 84 | + [μμΈ](modules.md) |
| 85 | + |
| 86 | +- **plugins** |
| 87 | + |
| 88 | + - μλ£ν: `Array<Function>` |
| 89 | + |
| 90 | + μ μ₯μμ μ μ© ν νλ¬κ·ΈμΈ ν¨μμ λ°°μ΄μ
λλ€. νλ¬κ·ΈμΈμ μ μ₯μλ₯Ό μ μΌν μ λ¬μΈμλ‘ λ°μλ€μ΄κ³ μμλ°μ΄λ λ°μ΄ν° μ§μμ±, λ‘κΉ
λλ λλ²κΉ
μ μν λ³μ΄λ₯Ό κ°μνκ±°λ (μΈλ°μ΄λ λ°μ΄ν° (μ: μΉ μμΌ λλ κ΄μ°° κ°λ₯ νλͺ©)μ λμ€ν¨μΉ λ³μ΄) κ°μν μ μμ΅λλ€. |
| 91 | + |
| 92 | + [μμΈ](plugins.md) |
| 93 | + |
| 94 | +- **strict** |
| 95 | + |
| 96 | + - μλ£ν: `Boolean` |
| 97 | + - κΈ°λ³Έκ°: `false` |
| 98 | + |
| 99 | + Vuex μ μ₯μλ₯Ό strict λͺ¨λλ‘ λ³κ²½ν©λλ€. strict λͺ¨λμμ λ³μ΄ νΈλ€λ¬ μΈλΆμ Vuex μνμ λν μμμ λ³μ΄λ μ€λ₯λ₯Ό λ°μμν΅λλ€. |
| 100 | + |
| 101 | + [μμΈ](strict.md) |
| 102 | + |
| 103 | +### Vuex.Store μΈμ€ν΄μ€ μμ± |
| 104 | + |
| 105 | +- **state** |
| 106 | + |
| 107 | + - μλ£ν: `Object` |
| 108 | + |
| 109 | + λ£¨νΈ μν. μ½κΈ° μ μ© |
| 110 | + |
| 111 | +- **getters** |
| 112 | + |
| 113 | + - μλ£ν: `Object` |
| 114 | + |
| 115 | + λ±λ‘λ getters μ
λλ€. μ½κΈ° μ μ©. |
| 116 | + |
| 117 | +### Vuex.Store μΈμ€ν΄μ€ λ©μλ |
| 118 | + |
| 119 | +- **`commit(type: string, payload?: any) | commit(mutation: Object)`** |
| 120 | + |
| 121 | + λ³μ΄λ₯Ό 컀λ°ν©λλ€. [μμΈ](mutations.md) |
| 122 | + |
| 123 | +- **`dispatch(type: string, payload?: any) | dispatch(action: Object)`** |
| 124 | + |
| 125 | + μ‘μ
μ λμ€ν¨μΉ ν©λλ€. λͺ¨λ νΈλ¦¬κ±°λ μ‘μ
νΈλ€λ¬λ₯Ό μ²λ¦¬νλ Promiseλ₯Ό λ°νν©λλ€. [μμΈ](actions.md) |
| 126 | + |
| 127 | +- **`replaceState(state: Object)`** |
| 128 | + |
| 129 | + μ μ₯μμ λ£¨νΈ μνλ₯Ό λ°κΏλλ€. μνμ λν μνΈμμ©/μμ λ³κ²½ λͺ©μ μΌλ‘ λ§ μ¬μ©νμμμ€. |
| 130 | + |
| 131 | +- **`watch(getter: Function, cb: Function, options?: Object)`** |
| 132 | + |
| 133 | + getter ν¨μμ λ°ν κ°μ λ°μμ μΌλ‘ μ§μΌλ³΄κ³ κ°μ΄ λ³κ²½λλ©΄ μ½λ°±μ νΈμΆν©λλ€. getterλ μ μ₯μμ μνλ₯Ό μ μΌν μΈμλ‘λ°μ΅λλ€. Vueμ `vm.$watch` λ©μλμ κ°μ μ΅μ
μ μ·¨νλ μ΅μ
κ°μ²΄λ₯Ό λ°μλ€μ
λλ€. |
| 134 | + |
| 135 | + κ°μλ₯Ό μ€λ¨νλ €λ©΄ λ°νλ νΈλ€ ν¨μλ₯Ό νΈμΆνμμμ€. |
| 136 | + |
| 137 | +- **`subscribe(handler: Function)`** |
| 138 | + |
| 139 | + μ μ₯μ λ³μ΄λ₯Ό ꡬλ
ν©λλ€. `handler`λ λͺ¨λ λ³μ΄ μ΄ν νΈμΆλκ³ λ³μ΄ λμ€ν¬λ¦½ν°μ λ³μ΄ μνλ₯Ό μ λ¬μΈμλ‘ λ°μ΅λλ€. |
| 140 | + |
| 141 | + ``` js |
| 142 | + store.subscribe((mutation, state) => { |
| 143 | + console.log(mutation.type) |
| 144 | + console.log(mutation.payload) |
| 145 | + }) |
| 146 | + ``` |
| 147 | + |
| 148 | + νλ¬κ·ΈμΈμμ κ°μ₯ μΌλ°μ μΌλ‘ μ¬μ©λ©λλ€. [μμΈ](plugins.md) |
| 149 | + |
| 150 | +- **`registerModule(path: string | Array<string>, module: Module)`** |
| 151 | + |
| 152 | + λμ λͺ¨λμ λ±λ‘ν©λλ€. [μμΈ](modules.md#dynamic-module-registration) |
| 153 | + |
| 154 | +- **`unregisterModule(path: string | Array<string>)`** |
| 155 | + |
| 156 | + λμ λͺ¨λμ ν΄μ ν©λλ€. [μμΈ](modules.md#dynamic-module-registration) |
| 157 | + |
| 158 | +- **`hotUpdate(newOptions: Object)`** |
| 159 | + |
| 160 | + μ μ‘μ
κ³Ό λ³μ΄λ₯Ό ν« μ€μ ν©λλ€. [μμΈ](hot-reload.md) |
| 161 | + |
| 162 | +### μ»΄ν¬λνΈ λ°μΈλ© ν¬νΌ |
| 163 | + |
| 164 | +- **`mapState(map: Array<string> | Object): Object`** |
| 165 | + |
| 166 | + Vuex μ μ₯μμ νμ νΈλ¦¬λ₯Ό λ°ννλ μ»΄ν¬λνΈ κ³μ° μ΅μ
μ λ§λλλ€. [μμΈ](state.md#the-mapstate-helper) |
| 167 | + |
| 168 | +- **`mapGetters(map: Array<string> | Object): Object`** |
| 169 | + |
| 170 | + getterμ νκ°λ κ°μ λ°ννλ μ»΄ν¬λνΈ κ³μ° μ΅μ
μ λ§λλλ€. [μμΈ](getters.md#the-mapgetters-helper) |
| 171 | + |
| 172 | +- **`mapActions(map: Array<string> | Object): Object`** |
| 173 | + |
| 174 | + μ‘μ
μ μ λ¬νλ μ»΄ν¬λνΈ λ©μλ μ΅μ
μ λ§λλλ€. [μμΈ](actions.md#dispatching-actions-in-components) |
| 175 | + |
| 176 | +- **`mapMutations(map: Array<string> | Object): Object`** |
| 177 | + |
| 178 | + λ³μ΄λ₯Ό 컀λ°νλ μ»΄ν¬λνΈ λ©μλ μ΅μ
μ λ§λλλ€. [μμΈ](mutations.md#commiting-mutations-in-components) |
0 commit comments