vue實現(xiàn)登錄界面
使用Vue實現(xiàn)簡單的用戶登錄界面,登錄成功以后查詢賬號用戶類型進行相應(yīng)的頁面路由跳轉(zhuǎn),效果如下圖所示:

HTML部分:
<div class="loginbody">
? ? <div class="login">
? ? ? <div class="mylogin" align="center">
? ? ? ? <h4>登錄</h4>
? ? ? ? <el-form
? ? ? ? ? :model="loginForm"
? ? ? ? ? :rules="loginRules"
? ? ? ? ? ref="loginForm"
? ? ? ? ? label-width="0px"
? ? ? ? >
? ? ? ? ? <el-form-item
? ? ? ? ? ? label=""
? ? ? ? ? ? prop="account"
? ? ? ? ? ? style="margin-top:10px;"
? ? ? ? ? >
? ? ? ? ? ? <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 style="margin-top:55px;">
? ? ? ? ? ? <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" 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;
? }以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
vue基于session和github-oauth2實現(xiàn)登錄注冊驗證思路詳解
通過 sessionId 可以在 session 表中獲取用戶的信息,此外,還利用 session 表實現(xiàn)了GitHub 的 OAuth2 第三方登錄,本文講解前端通過簡單的方式實現(xiàn)一個基本的登錄注冊驗證功能,感興趣的朋友跟隨小編一起看看吧2024-08-08
uniapp實現(xiàn)省市區(qū)三級級聯(lián)選擇功能(含地區(qū)json文件)
這篇文章主要給大家介紹了關(guān)于uniapp實現(xiàn)省市區(qū)三級級聯(lián)選擇功能(含地區(qū)json文件)的相關(guān)資料,級級聯(lián)是一種常見的網(wǎng)頁交互設(shè)計,用于省市區(qū)選擇,它的目的是方便用戶在一系列選項中進行選擇,并且確保所選選項的正確性和完整性,需要的朋友可以參考下2024-06-06
解決vue watch數(shù)據(jù)的方法被調(diào)用了兩次的問題
這篇文章主要介紹了解決vue watch數(shù)據(jù)的方法被調(diào)用了兩次的問題,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-11-11
Vue 中文本內(nèi)容超出規(guī)定行數(shù)后展開收起的處理的實現(xiàn)方法
這篇文章主要介紹了Vue 中文本內(nèi)容超出規(guī)定行數(shù)后展開收起的處理的實現(xiàn)方法,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-04-04
VUE3+Element-plus中el-form的使用示例代碼
這篇文章主要介紹了VUE3+Element-plus中el-form的使用示例代碼,本文通過圖文示例代碼相結(jié)合給大家介紹的非常詳細,需要的朋友可以參考下2024-07-07
vue-cli解決IE瀏覽器sockjs-client錯誤方法
這篇文章主要為大家介紹了vue-cli解決IE瀏覽器sockjs-client錯誤方法詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2023-08-08
Vue引入使用localforage改進本地離線存儲方式(突破5M限制)
這篇文章主要介紹了Vue引入使用localforage改進本地離線存儲方式(突破5M限制),具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2024-03-03

