Vue實(shí)現(xiàn)簡(jiǎn)單登錄界面
更新時(shí)間:2022年06月19日 06:43:52 作者:5210丫
這篇文章主要為大家詳細(xì)介紹了Vue實(shí)現(xiàn)簡(jiǎn)單登錄界面,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
本文實(shí)例為大家分享了Vue實(shí)現(xiàn)簡(jiǎn)單登錄界面的具體代碼,供大家參考,具體內(nèi)容如下
實(shí)現(xiàn):
- 界面實(shí)現(xiàn)
- 表單規(guī)則校驗(yàn)
- 結(jié)合后臺(tái) api 校驗(yàn)
- 提示消息
App.vue
<template>
? <div id="app">
<!--路由占位符 -->
? ?<router-view></router-view>
? </div>
</template>
<script>
export default {
? name: 'app'
}
</script>
<style>
</style>登錄頁(yè)面login.vue
<template>
?
? <div class="login_container">
?
? ? <div class="login_box">
? ? ? <div class="ava_box">
? ? ? ? <img src="../assets/logo.png" />
? ? ? </div>
? ? ? <!-- 賬號(hào) -->
? ? ? <el-form :model="loginForm" ref="loginFormRef" :rules="loginFormRules" label-width="0px" class="login_form">
? ? ? ? <el-form-item prop="username">
? ? ? ? ? <el-input ?v-model="loginForm.username" ?prefix-icon="el-icon-user-solid"></el-input>
? ? ? ? </el-form-item>
? ? ? ? <!-- 密碼 -->
? ? ? ? <el-form-item prop="password">
? ? ? ? ? <el-input ? v-model="loginForm.password" show-password="true" prefix-icon="el-icon-lock"></el-input>
? ? ? ? </el-form-item>
?
? ? ? ? <!-- 按鈕 -->
? ? ? ? <el-form-item class="btns">
? ? ? ? ? <el-button type="primary" @click="login" round>登錄</el-button>
? ? ? ? ? <!-- ? ? ?<el-button type="success" round>成功按鈕</el-button> -->
? ? ? ? ? <el-button type="info" @click="resetLoginForm" round>重置</el-button>
? ? ? ? </el-form-item>
? ? ? </el-form>
?
? ? </div>
?
? </div>
</template>
?
<script>
? export default {
? ? data(){
? ? ? return{
? ? ? ? // 表單數(shù)據(jù)綁定
? ? ? ? loginForm: {
? ? ? ? ? username: 'admin',
? ? ? ? ? password: '123456'
? ? ? ? },
? ? ? ? // 檢驗(yàn)規(guī)則
? ? ? ? loginFormRules: {
? ? ? ? ? username: [
? ? ? ? ? ? {required: true,message: '請(qǐng)輸入用戶名',trigger: 'blur'},
? ? ? ? ? ? { min: 3, max: 8, message: '長(zhǎng)度在 3 到 8 個(gè)字符', trigger: 'blur' }
? ? ? ? ? ],
? ? ? ? ? password: [
? ? ? ? ? ? ? {required: true,message: '密碼不能為空',trigger: 'blur'},
? ? ? ? ? ? ? ?{ min: 6, max: 12, message: '長(zhǎng)度在 6 到 12 個(gè)字符', trigger: 'blur' }
? ? ? ? ? ]
?
? ? ? ? }
? ? ? }
? ? },
? ? methods:{
? ? ? resetLoginForm(){
? ? ? ? this.$refs.loginFormRef.resetFields();
? ? ? },
? ? ? login(){
? ? ? ? this.$refs.loginFormRef.validate(async valid=>{
? ? ? ? ? ? console.log(valid);
? ? ? ? ? ? if(!valid) return;
? ? ? ? ? ? ?const {data: res}= await this.$http.post('login',this.loginForm);
? ? ? ? ? ? ?console.log(res)
? ? ? ? ? ? ?if(res.meta.status!=200) return this.$message.error('登錄失敗')
? ? ? ? ? ? this.$message.success('登錄成功')
?
? ? ? ? });
? ? ? }
? ? }
? }
</script>
<style lang="less" scoped>
?
? .login_container {
? ? background-color: #2b4b6b;
? ? height: 100%;
? }
?
? .login_box {
? ? height: 300px;
? ? width: 450px;
? ? background-color: #fff;
? ? border-radius: 3px;
? ? position: absolute;
? ? left: 50%;
? ? top: 50%;
? ? // 橫軸,縱軸
? ? transform: translate(-50%, -50%);
?
? ? .ava_box {
? ? ? height: 130px;
? ? ? width: 130px;
? ? ? border: 1px solid #eee;
? ? ? border-radius: 50%;
? ? ? padding: 10px;
? ? ? box-shadow: 0 0 10px #ddd;
? ? ? position: absolute;
? ? ? left: 50%;
? ? ? transform: translate(-50%, -50%);
? ? ? background-color: #fff;
?
? ? ? img {
? ? ? ? width: 100%;
? ? ? ? height: 100%;
? ? ? ? border-radius: 50%;
? ? ? ? background-color: #eee;
? ? ? }
? ? }
? ? .btns{
? ? ? display: flex;
? ? ? justify-content: flex-end;
?
? ? }
? ? .login_form{
? ? ? position: absolute;
? ? ? bottom: 0px;
? ? ? width: 100%;
? ? ? padding: 0 20px;
? ? ? box-sizing: border-box;
?
? ? }
? }
</style>element.js
import Vue from 'vue'
import { Button, Form, FormItem, Input,Message } from 'element-ui'
Vue.prototype.$message=Message
Vue.use(Button)
Vue.use(Form)
Vue.use(FormItem)
Vue.use(Input)
Vue.use(Message)main.js
import Vue from 'vue'
import App from './App.vue'
import router from './router'
import './plugins/element.js'
import './assets/css/global.css'
import axios from 'axios'
Vue.config.productionTip = false
axios.defaults.baseURL=''
Vue.prototype.$http=axios
new Vue({
? router,
? render: h => h(App)
}).$mount('#app')以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
vue中數(shù)組常用的6種循環(huán)方法代碼示例
在vue項(xiàng)目開發(fā)中,我們需要對(duì)數(shù)組進(jìn)行處理等問(wèn)題,這里簡(jiǎn)單記錄遍歷數(shù)組的幾種方法,這篇文章主要給大家介紹了關(guān)于vue中數(shù)組常用的6種循環(huán)方法,文中通過(guò)代碼介紹的非常詳細(xì),需要的朋友可以參考下2024-03-03
vue中阻止click事件冒泡,防止觸發(fā)另一個(gè)事件的方法
下面小編就為大家分享一篇vue中阻止click事件冒泡,防止觸發(fā)另一個(gè)事件的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-02-02
vue實(shí)現(xiàn)三級(jí)導(dǎo)航展示和隱藏
這篇文章主要為大家詳細(xì)介紹了vue實(shí)現(xiàn)三級(jí)導(dǎo)航展示和隱藏,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-08-08

