frp/web/src/store/modules/server.js

34 lines
596 B
JavaScript
Raw Normal View History

2020-12-04 01:08:40 +08:00
import Vue from 'vue'
import Vuex from 'vuex'
import fetch from '@/utils/fetch'
Vue.use(Vuex)
const state = {
serverInfo: null
}
const mutations = {
SET_SERVER_INFO(state, serverInfo) {
state.serverInfo = serverInfo
}
}
const actions = {
async fetchServerInfo({ commit }) {
2020-12-04 01:19:56 +08:00
const res = await fetch('serverinfo')
if (!res.ok) {
this.$message.warning('Get server info from frps failed!')
commit('SET_SERVER_INFO', null)
}
commit('SET_SERVER_INFO', (await res.json()) || null)
2020-12-04 01:08:40 +08:00
}
}
export default {
namespaced: true,
state,
mutations,
actions
}