溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

利用vue怎么實現(xiàn)一個登錄注冊功能

發(fā)布時間:2020-12-23 13:51:16 來源:億速云 閱讀:278 作者:Leah 欄目:開發(fā)技術

今天就跟大家聊聊有關利用vue怎么實現(xiàn)一個登錄注冊功能,可能很多人都不太了解,為了讓大家更加了解,小編給大家總結了以下內容,希望大家根據(jù)這篇文章可以有所收獲。

完整實例:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="GBK">
    <title></title>
    <style>
    ul li {
 
      margin: 0;
      padding: 0;
      list-style: none;
    }
    #app {
      width: 600px;
      height: 400px;
      margin: 0 auto;
      border: 1px solid #ccc;
    }
    .title{
    	text-align:center;
    }
    .tab-tilte{
      width: 99%;
    }
    .tab-tilte li{
      float: left;
      width: 31%;
      padding: 10px 0;
      text-align: center;
      background-color:#f4f4f4;
      cursor: pointer;
    }
   /* 點擊對應的標題添加對應的背景顏色 */
    .tab-tilte .active{
      background-color: #09f;
      color: #fff;
    }
    .tab-content div{
      float: left;
      width: 25%;
      line-height: 100px;
      text-align: center;
    }
    .sider_icon{
				display: inline-block;
				width:36px;
				height:40px;
				line-height:36px;
				font-size:20px;
				text-align:center;
				color:#fff;
				background: url(../images/bubble.png) 0 0 no-repeat;
				top:-20px;
			}
    	.contentli{
    		float: left;
	      padding: 10px 0;
	      text-align: center;
    	}
    	.input{
    		float: left;
    		width: 60%;
    		margin-left:20%;
	      padding: 10px 0;
	      align:center;
    	}
    	.btn{
    		float: left;
	      width: 20%;
	      margin-left:60%;
	      padding: 10px 1px;
	      text-align: center;
    	}
    	.guanggao{
    		float:right;
    		padding-right:10px;
    		cursor:pointer;
    	}
    	#bottomDiv{
    		float: left;
	      margin-left:40%;
	      padding: 10px 10px;
	      text-align: center;
    	}
    	#bottomDiv a{
    			 padding: 1px 10px;
    			 cursor:pointer;
    			 border-bottom:1px solid red;
    	}
    </style>
  </head>
  <body>
  	<div id="app" >
  		<div v-show='page==="advert"'>
  			<span class='guanggao' @click='goLogin'>點擊跳轉<b>{{n}}</b></span>
  			
  			<div id='bottomDiv'>
	  			<h2 class='title'>歡迎體驗</h2>
	  		</div>
  		</div>
  		<div v-show='page==="login"'>
	  		<div>
	  			<h2 class='title'>歡迎登錄</h2>
	  			<div>
		  			<input type="text" v-model='name' class="input" placeholder='請輸入用戶名'>
		  			<p v-show='!name'>請輸入用戶名</p>
	  			</div>
	  			<div>
	  			<input type="text" v-model='pwd' class="input" placeholder='請輸入密碼'>
	  			<p v-show='!pwd'>請輸入密碼</p>
	  			</div>
	  			<button @click="add" :disabled="!name||!pwd" class='btn'>登錄</button>
	  		</div>
	  		<div id='bottomDiv'>
	  			<a @click="goRegister">我要注冊</a>
	  		</div>
  		</div>
  		<div v-show='page==="register"'>
  			<div>
	  			<h2 class='title'>注冊界面,沒寫,哈哈</h2>
  			</div>
  			<div id='bottomDiv'>
	  			<a @click="goLogin">我要登錄</a>
	  		</div>
  		</div>
  		<div v-show='page==="suc"'>
  			<div>
	  			<h2 class='title'>登錄成功</h2>
  			</div>
  			<div id='bottomDiv'>
	  			<a @click="exit">退出登錄</a>
	  		</div>
  		</div>
		</div> 
  </body>
  <script src="vue.js"></script>
 	<script>
     new Vue({
      el:'#app',
      data:{
      	page:'advert',//默認是倒計時的顯示廣告 login/register 分別表示登錄、注冊
      	n:5,
      	intervalId:'',
      	name:'',
      	pwd:''
      },
      methods:{
      	autoPlay:function(){
      		//自動進行到計時
      		this.intervalId=setInterval(()=>{
      			if(this.n===0){//當?shù)褂嫊r為0的時候,跳轉登錄界面,并清除定時器
	      			this.page='login';//設置page為login
	      			clearInterval(this.intervalId);
	      			return ;
	      		}
	      		this.n--;
      		},1000);
      	},
      	goLogin:function(){//點擊到登錄界面
      		this.page='login';//設置page為login
      		clearInterval(this.intervalId);
      	},
      	add:function(){
      		//控制跳轉到成功
      		this.page='suc';
      	},
      	goRegister:function(){
      		//控制跳轉到注冊
      		this.page='register';
      		this.name=this.pwd='';
      	},
      	exit:function(){
      		//控制跳轉到登錄
      		this.page='login';
      		this.name=this.pwd='';
      	}	
      },
      computed:{
      	
      },
      mounted:function(){
      	//生命周期 mounted就執(zhí)行 倒計時函數(shù)
      	this.autoPlay();
      }
    })
 	</script>	
		
</html>

看完上述內容,你們對利用vue怎么實現(xiàn)一個登錄注冊功能有進一步的了解嗎?如果還想了解更多知識或者相關內容,請關注億速云行業(yè)資訊頻道,感謝大家的支持。

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng)、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經查實,將立刻刪除涉嫌侵權內容。

AI