<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>注册</title> </head> <body> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>欢迎注册</title> <link href="css/register.css" rel="stylesheet"> </head> <body> <div class="form-div" id="form-div"> <div class="reg-content"> <h1>欢迎注册</h1> <span>已有帐号?</span> <a href="index2.jsp">登录</a> </div> <form id="reg-form" action="" method="post"> <table> <tr> <td>用户名</td> <td class="inputs"> <input name="username" type="text" id="username" v-model="user.username"> </td> </tr> <tr> <td>密码</td> <td class="inputs"> <input name="password" type="password" id="password" v-model="user.password"> </td> </tr> <tr> <td>验证码</td> <td class="inputs"> <input name="checkCode" type="text" id="checkCode" v-model="user.checkcode" > <img id="checkCodeImg" src="/Login/user/checkCode" > <a href="" id="changeImg" >看不清?</a> <br> </td> </tr> </table> <div class="buttons"> <input value="注 册" type="button" id="reg_btn" @click="submitForm"> </div> <br class="clear"> </form> </div> <script src="js/axios-0.18.0.js"></script> <script src="js/vue.js"></script> <script src="element-ui/lib/index.js"></script> <link rel="stylesheet" href="element-ui/lib/theme-chalk/index.css"> <script> document.getElementById("changeImg").onclick = function () { document.getElementById("checkCodeImg").src = "/Login/user/checkCode?"+new Date().getMilliseconds(); } document.getElementById("checkCodeImg").onclick = function () { document.getElementById("checkCodeImg").src = "/Login/user/checkCode?"+new Date().getMilliseconds(); } </script> <script> new Vue({ el:"#form-div", data(){ return { user:{ username:"", password:"", checkcode:"" }, } }, methods:{ submitForm(){ console.log(this.user); // 发送ajax请求,添加 var _this=this; axios({ method:"post", url:"http://localhost:8080/Login/user/register", data:_this.user }).then(function (resp) { if(resp.data == "success") { location.href = "index.html"; } else if(resp.data == "error") _this.$message.error('账号已存在'); else _this.$message.error('验证码错误'); }) } } }) </script> </body> </html>
注册界面的搭建