html前端表单提交到某接口后(javaweb的接口),返回了字符串
{"Login":true}
请问如果利用vue处理该返回结果,实现成功登录的页面跳转?
html前端表单提交到某接口后(javaweb的接口),返回了字符串
{"Login":true}
请问如果利用vue处理该返回结果,实现成功登录的页面跳转?
首先在你的ajax回调函数中判断Login,根据规定好的内容提示不同信息,然后在验证成功后
进入其他页面this.$router.push('/index');注意this的指向。
this.$axios.post(`${this.sIP}/users`, this.loginForm).then((res) => {
//console.log(res.data)
if (res.data == '用户不存在' || res.data == '密码错误' || res.data == 'err') {
this.$message.error({
duration: 500,
showClose: true,
message: res.data,
type: 'error'
})
} else {
this.userToken = res.data.token;
//存储token
localStorage.setItem("token", res.data.token);
//解析token
let users = jwtDecode(res.data.token);
this.$store.dispatch('setisAuthenicated', !this.isEmpty(users));
this.$store.dispatch('setUsers', users);
//console.log(users)
this.$message({
showClose: true,
message: '登录成功',
type: 'success'
});
this.$router.push('/index');
}
})