1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
|
| import Vue from 'vue';
| import Vuex from 'vuex';
|
| Vue.use(Vuex);
|
| const store = new Vuex.Store({
| state: {
| // 其他模块的状态...
| },
| mutations: {
| // 其他模块的mutations...
| },
| actions: {
| // 其他模块的actions...
| },
| modules: {
| tag: {
| namespaced: true,
| state: {
| tags: [], // 标签列表
| selectedTag: null // 选中的标签
| },
| mutations: {
| SET_TAGS(state, tags) {
| state.tags = tags;
| },
| ADD_TAG(state, tag) {
| state.tags.push(tag);
| },
| REMOVE_TAG(state, tag) {
| state.tags = state.tags.filter(t => t !== tag);
| },
| CLEAR_TAGS(state) {
| state.tags = [];
| },
| SET_SELECTED_TAG(state, tag) {
| state.selectedTag = tag;
| },
| CLEAR_SELECTED_TAG(state) {
| state.selectedTag = null;
| }
| },
| actions: {
| setTags({ commit }, tags) {
| commit('SET_TAGS', tags);
| },
| addTag({ commit }, tag) {
| commit('ADD_TAG', tag);
| },
| removeTag({ commit }, tag) {
| commit('REMOVE_TAG', tag);
| },
| clearTags({ commit }) {
| commit('CLEAR_TAGS');
| },
| setSelectedTag({ commit }, tag) {
| commit('SET_SELECTED_TAG', tag);
| },
| clearSelectedTag({ commit }) {
| commit('CLEAR_SELECTED_TAG');
| }
| },
| getters: {
| getTags(state) {
| return state.tags;
| },
| getSelectedTag(state) {
| return state.selectedTag;
| }
| }
| }
| }
| });
|
| export default store;
|
|