前端axios发出的post请求如下
logout() {
this.axios.post(this.tools.serverAddr+'/logout')
.then(function () {
this.$message({
message: "注销成功",
type: 'success',
duration: 1000
});
this.$router.replace({
path: '/login'});
}.bind(this))
.catch(function (err) {
if (err.response) {
console.log(err.response)
}
}.bind(this))
},
后端spring security默认将/logout重定向到/login?logout,在前后端分离项目中会出现跨域请求问题
需要自定义对登出的处理
.logout()
//注销成功的处理
.logoutSuccessHandler(new LogoutSuccessHandler() {
@Override
public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {
printCode(response, 4);