|
|
@@ -68,6 +68,8 @@
|
|
|
params: this.loginForm
|
|
|
})
|
|
|
.then((data) => {
|
|
|
+ this.setCookie('username',this.loginForm.username);
|
|
|
+ this.setCookie('password',this.loginForm.password);
|
|
|
this.$message.success("登陆成功");
|
|
|
this.$router.push("/home/chat");
|
|
|
})
|
|
|
@@ -77,9 +79,37 @@
|
|
|
},
|
|
|
resetForm(formName) {
|
|
|
this.$refs[formName].resetFields();
|
|
|
- }
|
|
|
+ },
|
|
|
+ // 获取cookie、
|
|
|
+ getCookie(name) {
|
|
|
+ let reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
|
|
|
+ let arr = document.cookie.match(reg)
|
|
|
+ if (arr){
|
|
|
+ return (arr[2]);
|
|
|
+ }
|
|
|
+ return '';
|
|
|
+ },
|
|
|
+ // 设置cookie,增加到vue实例方便全局调用
|
|
|
+ setCookie (name, value, expiredays) {
|
|
|
+ var exdate = new Date();
|
|
|
+ exdate.setDate(exdate.getDate() + expiredays);
|
|
|
+ document.cookie = name + "=" + escape(value) + ((expiredays == null) ? "" : ";expires=" + exdate.toGMTString());
|
|
|
+ },
|
|
|
+ // 删除cookie
|
|
|
+ delCookie (name) {
|
|
|
+ var exp = new Date();
|
|
|
+ exp.setTime(exp.getTime() - 1);
|
|
|
+ var cval = this.getCookie(name);
|
|
|
+ if (cval != null){
|
|
|
+ document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ mounted() {
|
|
|
+ this.loginForm.username = this.getCookie("username");
|
|
|
+ // cookie存密码并不安全,暂时是为了方便
|
|
|
+ this.loginForm.password = this.getCookie("password");
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
</script>
|
|
|
|