vue编写一个登录页面,使用Tab栏实现“账号登录”和“二维码登录”这两种方式的切换

有时候,不是因为你没有能力,也不是因为你缺少勇气,只是因为你付出的努力还太少,所以,成功便不会走向你。而你所需要做的,就是坚定你的梦想,你的目标,你的未来,然后以不达目的誓不罢休的那股劲,去付出你的努力,成功就会慢慢向你靠近。

导读:本篇文章讲解 vue编写一个登录页面,使用Tab栏实现“账号登录”和“二维码登录”这两种方式的切换,希望对大家有帮助,欢迎收藏,转发!站点地址:www.bmabk.com,来源:原文

编写一个登录页面,使用Tab栏实现“账号登录”和“二维码登录”这两种方式的切换,并通过transition组件结合animate.css实现切换时的动画效果

1.CSS样式
编写自己想要的大小,颜色等

#content{
    width: 400px;;
    margin: 60px auto;
  }
  .title{
    height: 50px;
    border-bottom: 1px solid #e1e7ec;
    text-align: center;
  }
  #content a{
    text-decoration: none;
    color: black;
    font-size: 16px;
    background: #f1f1f1;
    padding: 5px 10px;
    margin: 0 10px;
    border-radius: 5px;
  }
  .form-input{
    height: 46px;
    line-height: 46px;
    margin-top: 10px;;
  }
  input{
    box-sizing: border-box;
    padding: 0 25px;
    background: #eef3f5;
    border-radius: 8px;
    width: 100%;
    height: 100%;
    border: 0;
    outline: 0;
    font-size: 14px;
  }
  #content .active{
    background-color: #09f;
    color: #fff;
  }
  .primary-button{
    background: linear-gradient(325deg,#4aa4ff,#1058fa);
    width: 100%;
    height: 42px;
    border-radius: 23px;
    border: 0;
    outline: none;
    color: #fff;
    letter-spacing: 10px;
    font-weight: 500;
    font-size: 16px;
    cursor: pointer;
    margin-top: 30px;
  }
  .pic{
    width: 200px;
    height: 200px;
    margin: 0 auto;
  }
  .pic img{
    width: 100%;
    height: 100%;
  }

2.页面结构

<!-- 定义登录组件 -->
  <template id="example1">
    <div> 
     <!-- 唯一的根容器 -->
     <div class="form-input">
       <input type="text" name="user" placeholder="请输入手机号/邮箱" class="form-input">
     </div>
     <div class="form-input">
         <input type="password" name="psd" placeholder="请输入密码" class="form-input">
     </div>
     <button type="button" class="primary-button"><span>登录</span></button>
    </div>
   </template>
   <!-- 二维码登录 -->
   <template id="example2">
     <div class="pic">
       <img src="./erweima.png">
     </div>
   </template>
   <div id="content">
     <div class="title">
       <a href="javascript:;" @click="compontentName = 'example1',cur=0" :class="{active:cur == 0}">账号登录</a>
       <a href="javascript:;" @click="compontentName = 'example2',cur=1" :class="{active:cur == 1}">二维码登录</a>
     </div>
     <transition enter-active-class="animated bounceInDown">
       <component :is="compontentName"></component>
     </transition>
   </div>

3.Javascript

    Vue.component('example1',{template:'#example1'})
    Vue.component('example2',{template:'#example2'})
    var vm = new Vue({
      el: '#content',
      data: { 
        compontentName :'example1',
        cur:0
        }
    });

全代码:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>登录</title>
    <script src="https://cdn.staticfile.org/vue/2.2.2/vue.min.js"></script>
    <link href="https://cdn.jsdelivr.net/npm/animate.css@3.5.1" rel="stylesheet" type="text/css">
<style>
  #content{
    width: 400px;;
    margin: 60px auto;
  }
  .title{
    height: 50px;
    border-bottom: 1px solid #e1e7ec;
    text-align: center;
  }
  #content a{
    text-decoration: none;
    color: black;
    font-size: 16px;
    background: #f1f1f1;
    padding: 5px 10px;
    margin: 0 10px;
    border-radius: 5px;
  }
  .form-input{
    height: 46px;
    line-height: 46px;
    margin-top: 10px;;
  }
  input{
    box-sizing: border-box;
    padding: 0 25px;
    background: #eef3f5;
    border-radius: 8px;
    width: 100%;
    height: 100%;
    border: 0;
    outline: 0;
    font-size: 14px;
  }
  #content .active{
    background-color: #09f;
    color: #fff;
  }
  .primary-button{
    background: linear-gradient(325deg,#4aa4ff,#1058fa);
    width: 100%;
    height: 42px;
    border-radius: 23px;
    border: 0;
    outline: none;
    color: #fff;
    letter-spacing: 10px;
    font-weight: 500;
    font-size: 16px;
    cursor: pointer;
    margin-top: 30px;
  }
  .pic{
    width: 200px;
    height: 200px;
    margin: 0 auto;
  }
  .pic img{
    width: 100%;
    height: 100%;
  }
</style>
</head>
<body>
    <!-- 定义登录组件 -->
  <template id="example1">
    <div> 
     <!-- 唯一的根容器 -->
     <div class="form-input">
       <input type="text" name="user" placeholder="请输入手机号/邮箱" class="form-input">
     </div>
     <div class="form-input">
         <input type="password" name="psd" placeholder="请输入密码" class="form-input">
     </div>
     <button type="button" class="primary-button"><span>登录</span></button>
    </div>
   </template>
   <!-- 二维码登录 -->
   <template id="example2">
     <div class="pic">
       <img src="./erweima.png">
     </div>
   </template>
   <div id="content">
     <div class="title">
       <a href="javascript:;" @click="compontentName = 'example1',cur=0" :class="{active:cur == 0}">账号登录</a>
       <a href="javascript:;" @click="compontentName = 'example2',cur=1" :class="{active:cur == 1}">二维码登录</a>
     </div>
     <transition enter-active-class="animated bounceInDown">
       <component :is="compontentName"></component>
     </transition>
   </div>
   <script>
    Vue.component('example1',{template:'#example1'})
    Vue.component('example2',{template:'#example2'})
    var vm = new Vue({
      el: '#content',
      data: { 
        compontentName :'example1',
        cur:0
        }
    });
  </script>   
</body>
</html>

vue编写一个登录页面,使用Tab栏实现“账号登录”和“二维码登录”这两种方式的切换

在这里插入图片描述

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/147484.html

(0)
飞熊的头像飞熊bm

相关推荐

发表回复

登录后才能评论
极客之音——专业性很强的中文编程技术网站,欢迎收藏到浏览器,订阅我们!