审查视图

src/vuex/store.js 1.2 KB
朱兆平 authored
1 2 3 4
import Vue from 'vue'
import Vuex from 'vuex'
import * as actions from './actions'
import * as getters from './getters'
王勇 authored
5
import {getServerList, getHostList} from "../api/message_bus"
朱兆平 authored
6 7 8 9 10

Vue.use(Vuex)

// 应用初始状态
const state = {
王勇 authored
11 12 13
    count: 10,
    serverList: [],
    virtualHostList: [],
朱兆平 authored
14 15 16 17
}

// 定义所需的 mutations
const mutations = {
王勇 authored
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
    StoreServerList(state) {
        getServerList().then((response) => {
            let res = response.data;
            if (res.code !== '200') {
                return;
            }
            // 获取服务器列表数据
            state.serverList = res.data;
        }).catch(error => {
            this.$message.error(error.toString());
        });
    },
    StoreHostList(state, serverId) {
        getHostList(serverId).then((response) => {
            let res = response.data;
            if (res.code !== '200') {
                return;
            }
            state.virtualHostList = res.data;
        }).catch(error => {
            this.$message.error(error.toString());
        });
    },

朱兆平 authored
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
    INCREMENT(state) {
        state.count++
    },
    DECREMENT(state) {
        state.count--
    }
}

// 创建 store 实例
export default new Vuex.Store({
    actions,
    getters,
    state,
    mutations
})