vue實現(xiàn)簡單的登錄彈出框
本文實例為大家分享了vue實現(xiàn)簡單的登錄彈出框的具體代碼,供大家參考,具體內(nèi)容如下
初學vue框架,小小的寫了一個登錄彈出框效果
各路大佬多多指教。
不多廢話,直接上代碼:
CSS:
*{margin:0;padding:0;}
/*登陸按鈕*/
#app{
width:140px;
height:36px;
margin:10px auto;
}
#login,#login a{
width: 200px;
height: 38px;
line-height:38px;
text-align: center;
text-decoration: none;
font-size: 24px;
color: #000;
}
/*登陸框*/
#login-box{
padding: 20px;
display:none;
width:350px;
height: 150px;
background: #eeeeee;
border-radius: 5px;
position: absolute;
margin-left: -80px;
margin-top: 150px;
}
#login-box>form{
text-align: center;
}
#login-box label{
display: block;
font-size: 20px;
margin: 10px 0 0 0;
}
#login-box label input{
width:200px;
height: 30px;
}
#login-box button{
width:200px;
height: 30px;
margin:10px 0 0 0;
width:90px;
border-radius: 5px;
}
#close{
font-size:18px;
position: absolute;
top:0;
right: 5px;
cursor: pointer;
}
/*背景*/
#back{
position:absolute;
left:0;
top:0;
width:100%;
height:100%;
background: #000;
opacity: 0.5;
}
HTML:
<div id="app"> <!--登陸按鈕--> <h3 id="login" v-if="isLogin==true">歡迎您 | <a href="javascript:;" @click="logout">注銷</a></h3> <h3 id="login" v-else><a href="javascript:;" @click="login1">登錄</a> | 注冊</h3> <!--登陸框 --> <div id="login-box" :style="log==0?'display:none':'display:block;zIndex:1'"> <form action=""> <label>用 戶: <input v-model="uname" type="text" placeholder="請輸入用戶名..."> </label> <label>密 碼: <input v-model="upwd" type="password" placeholder="請輸入密碼..."> </label> <button type="button" @click="login2">登錄</button> <p id="close" @click="close">×</p> </form> </div> <!--背景半透明處理--> <div id="back" :style="log==0?'display:none':'display:block'"></div> </div>
JS:
new Vue({
el:"#app",
data:{
isLogin:false,
log:0,
uname:"",
upwd:""
},
methods:{
login1(){
this.log=1;
},
login2(){
if(this.uname=="hahaha"&&this.upwd=="123456"){
this.log=0;
this.isLogin=true;
}else{
alert("用戶名或密碼不正確!");
}
},
close(){
this.log=0;
//清空input中的內(nèi)容
this.uname="";
this.upwd="";
},
logout(){
this.isLogin=false;
this.uname="";
this.upwd="";
}
}
})
效果圖如下:



正在學如何用vue與后臺連接,所以本例中的用戶名密碼都是寫死的,只是為了實現(xiàn)這個功能,進入實際運用還需改進。
小小地感嘆一下vue好方便。
關(guān)于vue.js組件的教程,請大家點擊專題vue.js組件學習教程進行學習。
更多vue學習教程請閱讀專題《vue實戰(zhàn)教程》
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Vue3+Vite項目引入Bootstrap5、bootstrap-icons方式
這篇文章主要介紹了Vue3+Vite項目引入Bootstrap5、bootstrap-icons方式,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2023-10-10
在Vue項目中用fullcalendar制作日程表的示例代碼
這篇文章主要介紹了在Vue項目中用fullcalendar制作日程表,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2019-08-08
vuex結(jié)合session存儲數(shù)據(jù)解決頁面刷新數(shù)據(jù)丟失問題
在項目中表單篩選項里,選擇完之后刷新頁面數(shù)據(jù)就變了,沒有保留在自己選擇的選項上。本文使用session存儲數(shù)據(jù),具有一定的參考價值,感興趣的可以了解一下2021-09-09
Vue——解決報錯 Computed property "****" was assigned to but it ha
這篇文章主要介紹了Vue——解決報錯 Computed property "****" was assigned to but it has no setter.的方法,幫助大家更好的理解和使用vue框架,感興趣的朋友可以了解下2020-12-12
proxy實現(xiàn)vue3數(shù)據(jù)雙向綁定原理
這篇文章主要介紹了proxy實現(xiàn)vue3數(shù)據(jù)雙向綁定原理,文章以介紹proxy的優(yōu)點開始展開全文內(nèi)容,圍繞proxy實現(xiàn)vue3數(shù)據(jù)雙向綁定的相關(guān)資料,,需要的朋友可以參考一下2021-12-12
關(guān)于vue使用ant design vue,打包后a-date-picker控件無法選擇日期的問題
這篇文章主要介紹了關(guān)于vite .env.test環(huán)境使用ant design vue,打包后a-date-picker控件無法選擇日期的問題,本文針對這個問題提供了解決方法,需要的朋友可以參考下2023-04-04

