首先获取登陆页面的标签以及按钮
其次验证数据输入格式
判断手机号输入格式是否正确,可以用正则表达式(
if(!(/^1[3-9]\d{9}$/.test(regTel))){
alert("手机号码有误,请重填");
return false;
}
)
(需要判断输入账号密码是否正确需要请求后端
axios.post('http+ip+端口号+文件仿制的地址里面', {
tel: logintelInput.value,
passwd: loginpwdInput.value
},{
withCredentials: true//允许跨域携带凭证(cookie)
})
.then(function (response) {
console.log(response);
if(response.data.code == 1){//登录成功
alert('登录成功')
// 隐藏弹窗
userform.style.visibility = 'hidden';
// 隐藏登录注册按钮,显示人的小图标
navHeadImg.style.display = 'inline-block';
showuser.style.display = 'none';
// 设置cookie
//这里用到了session携带的cookie存储密码账号,需要给cookie设置允许跨域携带凭证
// setCookie('loginstates',1,7);
setCookie('account',response.data.data.tel,7);
}else{
alert(response.data.data);
}
})
.catch(function (error) {
console.log(error);
});
)