1. 程式人生 > 程式設計 >vue實現登入、註冊、退出、跳轉等功能

vue實現登入、註冊、退出、跳轉等功能

本文給大家介紹vue實現登入、註冊、退出、跳轉功能,具體程式碼如下所示:

效果圖1:

vue實現登入、註冊、退出、跳轉等功能

效果圖2:

vue實現登入、註冊、退出、跳轉等功能

效果圖3:

vue實現登入、註冊、退出、跳轉等功能

效果圖4:

vue實現登入、註冊、退出、跳轉等功能

完整例項:

<!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'>點選跳轉{{n}}</span>
  			
  			<div id='bottomDiv'>
	  			<h1 class='title'>歡迎體驗</h1>
	  		</div>
  		</div>
  		<div v-show='page==="login"'>
	  		<div>
	  			<h1 class='title'>歡迎登入</h1>
	  			<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>
	  			<h1 class='title'>註冊介面,沒寫,哈哈</h1>
  			</div>
  			<div id='bottomDiv'>
	  			<a @click="goLogin">我要登入</a>
	  		</div>
  		</div>
  		<div v-show='page==="suc"'>
  			<div>
	  			<h1 class='title'>登入成功</h1>
  			</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){//當倒計時為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就執行 倒計時函式
      	this.autoPlay();
      }
    })
 	</script>	
		
</html>

到此這篇關於vue實現登入、註冊、退出、跳轉等功能的文章就介紹到這了,更多相關vue實現登入、註冊、退出、跳轉內容請搜尋我們以前的文章或繼續瀏覽下面的相關文章希望大家以後多多支援我們!