完善注册信息前端内容
This commit is contained in:
+37
-4
@@ -7,6 +7,7 @@ export default {
|
||||
photo: "",
|
||||
token: "",
|
||||
is_login: false,
|
||||
pulling_info: true, // 当前是否在获取信息
|
||||
},
|
||||
getters: {},
|
||||
// 同步事件
|
||||
@@ -30,6 +31,10 @@ export default {
|
||||
state.token = "";
|
||||
state.is_login = false;
|
||||
},
|
||||
// 更新信息拉取状态
|
||||
updatePullingInfo(state, pulling_info) {
|
||||
state.pulling_info = pulling_info;
|
||||
},
|
||||
},
|
||||
// 异步事件
|
||||
actions: {
|
||||
@@ -43,12 +48,14 @@ export default {
|
||||
password: data.password,
|
||||
},
|
||||
success(resp) {
|
||||
// console.log(resp.token, "\n成功了\n", resp.error_message);
|
||||
// console.log(resp.token, "\n成功了\n", resp.error_message);
|
||||
if (resp.error_message === "success") {
|
||||
// 将登陆成功的信息存到 localStorage 中,用于浏览器的登录信息持久化(避免刷新后登录状态丢失)
|
||||
localStorage.setItem("jwt_token", resp.token);
|
||||
/*
|
||||
登录成功则将获取到的 resp 里的 token 传给 mutations 里的
|
||||
updateToken 方法,对用户 token 信息进行更新
|
||||
*/
|
||||
登录成功则将获取到的 resp 里的 token 传给 mutations 里的
|
||||
updateToken 方法,对用户 token 信息进行更新
|
||||
*/
|
||||
context.commit("updateToken", resp.token);
|
||||
data.success(resp);
|
||||
} else {
|
||||
@@ -60,6 +67,30 @@ export default {
|
||||
},
|
||||
});
|
||||
},
|
||||
|
||||
// 注册函数
|
||||
register(context, data) {
|
||||
$.ajax({
|
||||
url: "http://localhost:3000/user/account/register/",
|
||||
type: "POST",
|
||||
data: {
|
||||
username: data.username,
|
||||
password: data.password,
|
||||
confirmedPassword: data.confirmedPassword,
|
||||
},
|
||||
success(resp) {
|
||||
if (resp.error_message === "successRegister") {
|
||||
data.success(resp);
|
||||
} else {
|
||||
data.error(resp);
|
||||
}
|
||||
},
|
||||
error(resp) {
|
||||
data.error(resp);
|
||||
},
|
||||
});
|
||||
},
|
||||
|
||||
// 获取登录成功后的用户信息
|
||||
getinfo(context, data) {
|
||||
$.ajax({
|
||||
@@ -86,6 +117,8 @@ export default {
|
||||
});
|
||||
},
|
||||
logout(context) {
|
||||
// 退出时,删除 localStorage 里的持久化信息
|
||||
localStorage.removeItem("jwt_token");
|
||||
context.commit("logout");
|
||||
},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user