如何利用vue+element?ui實(shí)現(xiàn)好看的登錄界面
閑暇之余使用vue+element ui制作了個(gè)登錄界面
話不多說,先上
界面效果圖

下面直接上代碼:
<template>
<div class="loginbody">
<div class="logindata">
<div class="logintext">
<h2>Welcome</h2>
</div>
<div class="formdata">
<el-form ref="form" :model="form" :rules="rules">
<el-form-item prop="username">
<el-input
v-model="form.username"
clearable
placeholder="請輸入賬號(hào)"
></el-input>
</el-form-item>
<el-form-item prop="password">
<el-input
v-model="form.password"
clearable
placeholder="請輸入密碼"
show-password
></el-input>
</el-form-item>
</el-form>
</div>
<div class="tool">
<div>
<el-checkbox v-model="checked" @change="remenber"
>記住密碼</el-checkbox
>
</div>
<div>
<span class="shou" @click="forgetpas">忘記密碼?</span>
</div>
</div>
<div class="butt">
<el-button type="primary" @click.native.prevent="login('form')"
>登錄</el-button
>
<el-button class="shou" @click="register">注冊</el-button>
</div>
</div>
</div>
</template>
<script>
import { login } from "@/api/login";
import { setToken } from "@/request/auth";
export default {
name: "login",
data() {
return {
form: {
password: "",
username: "",
},
checked: false,
rules: {
username: [
{ required: true, message: "請輸入用戶名", trigger: "blur" },
{ max: 10, message: "不能大于10個(gè)字符", trigger: "blur" },
],
password: [
{ required: true, message: "請輸入密碼", trigger: "blur" },
{ max: 10, message: "不能大于10個(gè)字符", trigger: "blur" },
],
},
};
},
mounted() {
if(localStorage.getItem("news")){
this.form=JSON.parse(localStorage.getItem("news"))
this.checked=true
}
},
methods: {
login(form) {
this.$refs[form].validate((valid) => {
if (valid) {
login(this.form)
.then((res) => {
if (res.code === 200) {
setToken(res.data.token);
localStorage.setItem("USERNAME", res.data.username);
this.$message({
message: "登錄成功啦",
type: "success",
showClose: true,
});
this.$router.replace("/");
} else {
this.$message({
message: "賬戶名或密碼錯(cuò)誤",
type: "error",
showClose: true,
});
}
})
.catch((err) => {
this.$message({
message: "賬戶名或密碼錯(cuò)誤",
type: "error",
showClose: true,
});
});
} else {
return false;
}
});
},
remenber(data){
this.checked=data
if(this.checked){
localStorage.setItem("news",JSON.stringify(this.form))
}else{
localStorage.removeItem("news")
}
},
forgetpas() {
this.$message({
type:"info",
message:"功能尚未開發(fā)額??",
showClose:true
})
},
register() {},
},
};
</script>
<style scoped>
.loginbody {
width: 100%;
height: 100%;
min-width: 1000px;
background-image: url("../assets/login2.jpg");
background-size: 100% 100%;
background-position: center center;
overflow: auto;
background-repeat: no-repeat;
position: fixed;
line-height: 100%;
padding-top: 150px;
}
.logintext {
margin-bottom: 20px;
line-height: 50px;
text-align: center;
font-size: 30px;
font-weight: bolder;
color: white;
text-shadow: 2px 2px 4px #000000;
}
.logindata {
width: 400px;
height: 300px;
transform: translate(-50%);
margin-left: 50%;
}
.tool {
display: flex;
justify-content: space-between;
color: #606266;
}
.butt {
margin-top: 10px;
text-align: center;
}
.shou {
cursor: pointer;
color: #606266;
}
/*ui*/
/* /deep/ .el-form-item__label {
font-weight: bolder;
font-size: 15px;
text-align: left;
}
/deep/ .el-button {
width: 100%;
margin-bottom: 10px;
} */
</style>附加背景圖片

總結(jié)
到此這篇關(guān)于如何利用vue+element ui實(shí)現(xiàn)好看的登錄界面的文章就介紹到這了,更多相關(guān)vue+element ui登錄界面內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
el-input設(shè)置后綴顯示單位并阻止?jié)L輪微調(diào)的解決方法
在Element UI或Element Plus中,使用el-input組件時(shí),可以通過suffix插槽添加單位顯示,如果設(shè)置了type為'number',滾輪滾動(dòng)可能會(huì)導(dǎo)致數(shù)值微調(diào),解決方法是阻止?jié)L輪事件的默認(rèn)行為,并用CSS隱藏掉輸入框的上下箭頭,確保數(shù)值輸入的準(zhǔn)確性,這樣既美觀又提升了用戶體驗(yàn)2024-09-09
vue3項(xiàng)目啟動(dòng)自動(dòng)打開瀏覽器以及server配置過程
這篇文章主要介紹了vue3項(xiàng)目啟動(dòng)自動(dòng)打開瀏覽器以及server配置過程,具有很好的參考價(jià)值,希望對大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-03-03
vue-cli的webpack模板項(xiàng)目配置文件分析
本篇文章主要對vue-cli的webpack模板項(xiàng)目配置文件進(jìn)行分析。具有很好的參考價(jià)值。下面跟著小編一起來看下吧2017-04-04
vue監(jiān)聽瀏覽器原生返回按鈕,進(jìn)行路由轉(zhuǎn)跳操作
這篇文章主要介紹了vue監(jiān)聽瀏覽器原生返回按鈕,進(jìn)行路由轉(zhuǎn)跳操作,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-09-09
Vue3+Element-Plus?實(shí)現(xiàn)點(diǎn)擊左側(cè)菜單時(shí)顯示不同內(nèi)容組件展示在Main區(qū)域功能
這篇文章主要介紹了Vue3+Element-Plus?實(shí)現(xiàn)點(diǎn)擊左側(cè)菜單時(shí)顯示不同內(nèi)容組件展示在Main區(qū)域功能,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2023-01-01
Vue數(shù)據(jù)改變但頁面沒有變的幾種情況及解決方法
如果,你發(fā)現(xiàn)自己需要在Vue中做一次強(qiáng)制更新,99.99%的情況,是你在某個(gè)地方做錯(cuò)了事,所以本文給大家介紹了Vue數(shù)據(jù)改變但頁面沒有變的幾種情況及解決方法,文中通過代碼示例介紹的非常詳細(xì),需要的朋友可以參考下2024-11-11
Vue如何實(shí)現(xiàn)將后端返回二進(jìn)制文件在瀏覽器自動(dòng)下載
Vue項(xiàng)目開發(fā)中,遇到界面下載功能時(shí),前端如何實(shí)現(xiàn)將后端返回二進(jìn)制文件在瀏覽器自動(dòng)下載呢,本文就來和大家聊聊具體的解決方法吧2024-11-11
vite項(xiàng)目添加eslint?prettier及husky方法實(shí)例
這篇文章主要為大家介紹了vite項(xiàng)目添加eslint?prettier及實(shí)例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-07-07

