- local.js
export default {//处理localStorage
get(name){
return window.JSON.parse(window.localStorage.getItem(name));
},
set(name, content){
window.localStorage.setItem(name, window.JSON.stringify(content));
}
}
- store.js
import local from './public/local'
mutations:{
fn_token(state, arg){
state.token = arg;
local.set('token', arg);
}
},
- App.vue
import {mapMutations} from 'vuex'
import local from '../public/local'
methods:{
...mapMutations({
fn_token:'fn_token'
}),
}
create(){
this.fn_token(local.get('token'));
}
提示:sessionStorage同上理。