登录后跳转至之前访问界面(暂只支持文章详情页+个人主页)

This commit is contained in:
ronger 2020-12-18 14:20:07 +08:00
parent b79977863c
commit 1335dd9786
2 changed files with 139 additions and 130 deletions

View File

@ -69,7 +69,8 @@
},
forget: false,
loading: false,
loginLoading: false
loginLoading: false,
historyUrl: ''
}
},
computed: {
@ -113,10 +114,14 @@
localStorage.setItem('user', JSON.stringify(user))
_ts.$store.commit('setUser', user) // mutating to store for client rendering
Cookie.set('auth', auth)
if (_ts.historyUrl) {
window.location.href = _ts.historyUrl
} else {
_ts.$router.push({
name: 'index'
})
}
}
})
} else {
return false;
@ -158,7 +163,8 @@
}
},
mounted() {
this.$store.commit('setActiveMenu', 'login')
this.$store.commit('setActiveMenu', 'login');
this.$set(this, 'historyUrl', this.$route.query.historyUrl || '');
}
}
</script>

View File

@ -22,12 +22,12 @@
<div v-if="oauth.idUser !== user.idUser">
<el-button type="primary" v-if="isFollow" @click="cancelFollowUser(user.idUser)" plain>取消关注</el-button>
<el-button type="primary" v-else @click="followUser(user.idUser)" plain>关注</el-button>
<el-button @click="gotoChats" plain>聊天</el-button>
<el-button v-show="false" @click="gotoChats" plain>聊天</el-button>
</div>
</div>
<div v-else>
<el-button type="primary" @click="login" plain>关注</el-button>
<el-button @click="login" plain>聊天</el-button>
<el-button v-show="false" @click="login" plain>聊天</el-button>
</div>
</div>
</div>
@ -151,7 +151,10 @@ export default {
},
login() {
this.$router.push({
path: '/login'
path: '/login',
query: {
historyUrl: window.location.href
}
})
}
},