1、第一次登录的时候,前端调后端的登陆接口,发送用户名和密码
2、后端收到请求,验证用户名和密码,验证成功,就给前端返回一个token
3、前端拿到token,将token存储到localStorage中,并跳转路由页面
4、前端每次跳转路由,就判断 localStroage 中有无 token ,没有就跳转到登录页面,有则跳转到对应路由页面
调登录接口成功,在回调函数中将token存储到localStorage中
methods: {
submitForm(formName) {
this.$refs[formName].validate(valid => {
console.log(111)
if (valid) {
//调用登录接口
loginApi.login(this.form.username, this.form.password).then(response => {
const resp = response.data;
console.log(resp);
if(resp