您好,登錄后才能下訂單哦!
本文小編為大家詳細介紹“vue如何實現登錄界面”,內容詳細,步驟清晰,細節處理妥當,希望這篇“vue如何實現登錄界面”文章能幫助大家解決疑惑,下面跟著小編的思路慢慢深入,一起來學習新知識吧。
效果如下圖所示:
HTML部分:
<div class="loginbody"> <div class="login"> <div class="mylogin" align="center"> <h5>登錄</h5> <el-form :model="loginForm" :rules="loginRules" ref="loginForm" label-width="0px" > <el-form-item label="" prop="account" > <el-row> <el-col :span='2'> <span class="el-icon-s-custom"></span> </el-col> <el-col :span='22'> <el-input class="inps" placeholder='賬號' v-model="loginForm.account"> </el-input> </el-col> </el-row> </el-form-item> <el-form-item label="" prop="passWord" > <el-row> <el-col :span='2'> <span class="el-icon-lock"></span> </el-col> <el-col :span='22'> <el-input class="inps" type="password" placeholder='密碼' v-model="loginForm.passWord" ></el-input> </el-col> </el-row> </el-form-item> <el-form-item > <el-button type="primary" round class="submitBtn" @click="submitForm" >登錄 </el-button> </el-form-item> <div class="unlogin"> <router-link :to="{ path: '/forgetpwd'}"> 忘記密碼? </router-link> | <router-link :to="{path: '/register'}"> <a href="register.vue" rel="external nofollow" target="_blank" align="right">注冊新賬號</a> </router-link> </div> </el-form> </div> </div> </div>
JS部分
import {mapMutations} from "vuex"; export default { name: "Login", data: function () { return { loginForm: { account: '', passWord: '' }, loginRules: { account: [ {required: true, message: "請輸入賬號", trigger: "blur"} ], passWord: [{required: true, message: "請輸入密碼", trigger: "blur"}] } } }, methods: { ...mapMutations(['changeLogin']), submitForm() { let self = this; const userAccount = this.loginForm.account; const userPassword = this.loginForm.passWord; const userForm = new FormData(); userForm.append('userAccount', userAccount); userForm.append('userPassword', userPassword); this.axios.post('URL1', userForm ).then((res) => { if (res.data == 0) { self.$message({ type: 'error', message: '密碼錯誤,登陸失敗!' }) } //token self.sessiontoken = res.headers['sessiontoken']; self.PageToken = Math.random().toString(36).substr(2); sessionStorage.setItem('PageToken', self.PageToken); self.changeLogin({sessiontoken: self.sessiontoken}); //登錄成功 if (res.data == 1) { self.axios.get("URL2" ).then((res) => { if (res.data == null) { self.$message({ type: 'error', message: '查詢失敗!' }) } else { if (res.data.userType == 0) { self.$router.push({path: '/supermana', replace: true}) } else if (res.data.userType == 1) { self.$router.push({path: '/manauser', replace: true}) } else if (res.data.userType == 2) { self.$router.push({path: '/ordinauser', replace: true}) } } }).catch((error) => { console.log(error) }) } }) }, } }
CSS部分
.loginbody { overflow: scroll; overflow-y: hidden; overflow-x: hidden; } .login { width: 100vw; padding: 0; margin: 0; height: 100vh; font-size: 16px; background-position: left top; background-color: #242645; color: #fff; font-family: "Source Sans Pro"; position: relative; background-image: url('/static/images/background.jpg'); background-repeat: no-repeat; background-size: 100% 100%; } .mylogin { width: 240px; height: 280px; position: absolute; top: 0; left: 0; right: 0; bottom: 0; margin: auto; padding: 50px 40px 40px 40px; box-shadow: -15px 15px 15px rgba(6, 17, 47, 0.7); opacity: 1; background: linear-gradient( 230deg, rgba(53, 57, 74, 0) 0%, rgb(0, 0, 0) 100% ); } .inps input { border: none; color: #fff; background-color: transparent; font-size: 12px; } .submitBtn { background-color: transparent; color: #39f; width: 200px; }
讀到這里,這篇“vue如何實現登錄界面”文章已經介紹完畢,想要掌握這篇文章的知識點還需要大家自己動手實踐使用過才能領會,如果想了解更多相關內容的文章,歡迎關注億速云行業資訊頻道。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。