以前我是只在mutations里面修改state,然后页面dispatch调用action之后,再做sessionStorage(当前登录的用户信息)和localStorage(token存储)的一些操作。最近突然有点偷懒,我把sessionStorage和localStorage的相关操作都写到mutations里面去了,比如mutations: {
SET_TOKEN: (state, token) => {
state.token = token;
localStorage.setItem('token', token);
},
SET_USER_INFO: (state, admin) => {
state.admin_id = admin.admin_id;
state.admin_name = admin.admin_name;
state.email = admin.email;
state.avatar = admin.avatar;
sessionStorage.setItem('admin', JSON.stringify(admin));
},
//……
}这样就统一了,调用之后,就不需要在vue页面再操作localStorage和sessionStorage了。我想知道的是,这样符合规范吗?
添加回答
举报
0/150
提交
取消