1、修改default.vue页面脚本
export default { data() { return { token: '', loginInfo: { id: '', age: '', avatar: '', mobile: '', nickname: '', sex: '' } } }, created() { this.token = this.$route.query.token if (this.token) { this.wxLogin() } this.showInfo() }, methods: { showInfo() { //debugger var jsonStr = cookie.get("guli_ucenter"); if (jsonStr) { this.loginInfo = JSON.parse(jsonStr) } }, logout() { //debugger cookie.set('guli_ucenter', "", {domain: 'localhost'}) cookie.set('guli_token', "", {domain: 'localhost'}) //跳转页面 window.location.href = "/" }, wxLogin() { if (this.token == '') return //把token存在cookie中、也可以放在localStorage中 cookie.set('guli_token', this.token, {domain: 'localhost'}) cookie.set('guli_ucenter', '', {domain: 'localhost'}) //登录成功根据token获取用户信息 userApi.getLoginInfo().then(response => { this.loginInfo = response.data.data.item //将用户信息记录cookie cookie.set('guli_ucenter', this.loginInfo, {domain: 'localhost'}) }) } }}