提交 | 用户 | 时间
|
fd2207
|
1 |
const state = { |
懒 |
2 |
dict: new Array() |
|
3 |
} |
|
4 |
const mutations = { |
|
5 |
SET_DICT: (state, { key, value }) => { |
|
6 |
if (key !== null && key !== "") { |
|
7 |
state.dict.push({ |
|
8 |
key: key, |
|
9 |
value: value |
|
10 |
}) |
|
11 |
} |
|
12 |
}, |
|
13 |
REMOVE_DICT: (state, key) => { |
|
14 |
try { |
|
15 |
for (let i = 0; i < state.dict.length; i++) { |
|
16 |
if (state.dict[i].key == key) { |
|
17 |
state.dict.splice(i, 1) |
|
18 |
return true |
|
19 |
} |
|
20 |
} |
|
21 |
} catch (e) { |
|
22 |
} |
|
23 |
}, |
|
24 |
CLEAN_DICT: (state) => { |
|
25 |
state.dict = new Array() |
|
26 |
} |
|
27 |
} |
|
28 |
|
|
29 |
const actions = { |
|
30 |
// 设置字典 |
|
31 |
setDict({ commit }, data) { |
|
32 |
commit('SET_DICT', data) |
|
33 |
}, |
|
34 |
// 删除字典 |
|
35 |
removeDict({ commit }, key) { |
|
36 |
commit('REMOVE_DICT', key) |
|
37 |
}, |
|
38 |
// 清空字典 |
|
39 |
cleanDict({ commit }) { |
|
40 |
commit('CLEAN_DICT') |
|
41 |
} |
|
42 |
} |
|
43 |
|
|
44 |
export default { |
|
45 |
namespaced: true, |
|
46 |
state, |
|
47 |
mutations, |
|
48 |
actions |
|
49 |
} |
|
50 |
|