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

编写一个登录页面,使用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>

在这里插入图片描述

  • 25
    点赞
  • 122
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
好的,我理解了你的要求。以下是一个简单的实现示例: ```html <template> <div class="login-container"> <!-- Tab --> <div class="tab-bar"> <div class="tab-item" :class="{ active: loginType === 'account' }" @click="loginType = 'account'" > 账号登录 </div> <div class="tab-item" :class="{ active: loginType === 'qrCode' }" @click="loginType = 'qrCode'" > 二维码登录 </div> </div> <!-- 登录表单 --> <transition name="fade"> <div v-if="loginType === 'account'" class="login-form account"> <!-- 账号登录表单 --> </div> <div v-else class="login-form qr-code"> <!-- 二维码登录表单 --> </div> </transition> </div> </template> <script> export default { data() { return { loginType: 'account', // 当前登录类型 }; }, }; </script> <style lang="scss"> .login-container { .tab-bar { display: flex; justify-content: space-between; margin-bottom: 20px; .tab-item { padding: 10px; cursor: pointer; &.active { color: #1890ff; border-bottom: 2px solid #1890ff; } } } .login-form { &.account { /* 账号登录表单样式 */ } &.qr-code { /* 二维码登录表单样式 */ } } /* 切换动画 */ .fade-enter-active, .fade-leave-active { transition: opacity 0.5s; } .fade-enter, .fade-leave-to { opacity: 0; } } </style> ``` 在这个示例中,我们通过一个 `loginType` 变量来记录当前的登录方式。点击 Tab 中的不同选项,就可以切换登录方式了。 为了实现切换时的动画效果,我们使用Vue 的过渡动画(`<transition>`)和 animate.css 库。在 `<transition>` 中,我们使用了 `name="fade"` 属性来指定动画的类名。在样式中,我们定义了 `.fade-enter-active`、`.fade-leave-active`、`.fade-enter` 和 `.fade-leave-to` 四个类,来指定动画效果和过程。在 `login-form` 元素中,我们使用了 `v-if` 来根据当前的 `loginType` 变量来判断要显示哪个表单。这样,当我们切换 Tab 时,就能实现过渡动画了。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

南蓬幽

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值