需要准备的东西Vue+axios+Vuex+Vue-router
1.在login.vue中通过发送http请求获取token
//根据api接口获取token
var url = this.HOST + "/session";
this.$axios.post(url, {
username: this.loginForm.username,
password: this.loginForm.pass
}).then(res => {
// console.log(res.data);
this.$message.success('登录成功');
let data = res.data;
//根据store中set_token方法将token保存至localStorage/sessionStorage中,data["Authentication-Token"],获取token的value值
this.$store.commit('set_token', data["Authentication-Token"]);
if (store.state.token) {
this.$router.push('/')
console.log(store.state.token)
} else {
this.$router.replace('/login');
}
}).catch(error => {
// this.$message.error(error.status)
this.loading = false
this.loginBtn = "登录"
thi