Сделать экшн, в котором выполнить запрос.
actions.loadMenu = async ({ commit, state }, payload) => {
if (!state.menus[payload.menu] || payload.force) {
let response = await Vue.axios.get('/menu/' + payload.menu);
if (response.status === 200) {
commit('setMenu', { menu: payload.menu, data: response.data });
}
}
};
UPDATE:store.jsimport axios from 'axios';
export default new vuex.Store({
state: {
params: null,
},
mutations:{
setParams(state, payload){
state.params = payload;
}
},
actions: {
async getParams({comit, state}){
let response = await axios.get('information/account');
if (response.status === 200) {
commit('setParams', response.data);
}
}
}
});
IdWeb.vueimport { mapState } from 'vuex';
export default {
name: 'IdWeb',
computed: {
...mapState([
'params'
])
},
mounted() {
this.$store.dispath('getParams');
},
}
<template>
<li class="state_account_id" v-if="params">
ID: {{params.id}}
</li>
</template>