正常情况用户登录成功将token保存在localstorage中,登陆成功了但是localstorage中没token信息
后端返回的token:
token为null
login.vue
import axios from 'axios'
import store from '@/vuex/store'
import * as types from '@/vuex/types'
submitForm(formname) {
var _this = this;
this.$refs[formname].validate((valid) => {
if (valid) {
axios.post('/api/users', {
username: this.form.email,
password: this.form.password,
action: 'login'
})
.then(function(res){
store.commit('types.LOGIN', res['data']);
console.log(store);
_this.$router.push('/dashboard');
})
.catch(function(err){
console.log(err);
_this.noticeBox('用户名或密码不正确');
});
}else{
console.log('error submit!!');
return false;
}
});
},
store.js
import Vue from 'vue'
import Vuex from 'vuex'
import * as types from './types'
Vue.use(Vuex);
const state = {
user: {},
token: null,
title: ''
}
const mutations = {
[types.LOGIN]: (state, data) => {
localStorage.token = data;
state.token = data;
},
[types.LOGOUT]: (state) => {
localStorage.removeItem('token');
state.token = null;
}
}
export default new Vuex.Store({
state,
mutations
})