// router.js
import store from './store';
router.beforeEach((to, from, next) => {
if (!store.getters.token) {
next({ path: '/login' });
} else {
next();
}
});
// store
const state = {
token: localStorage.getItem('token'),
};
const getters = {
token(state) {
return state.token;
},
};
const str = JSON.stringify(this.postBody);
axios.post('http://localhost:8081/', str)
.then((response) => {
console.log(response);
})
.catch((error) => {
console.log(error);
});
this.$store.dispatch('showNotification', { type: 'Success', message: 'Item was renamed!' });
isItemsReady
в модуле с значением false, после того как данные стянулись и сохранились, тригерите его в true. Это вам понадобиться на страницах/компонентах, чтобы узнать что данные готовы, можно пока isItemsReady
false крутить спиннер.items: { return this.$store.getters.items }