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

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

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

1.CSS样式

编写自己想要的大小,颜色等


```html

#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.页面结构


```html

<!-- 定义登录组件 -->

 <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


```html

   Vue.component('example1',{template:'#example1'})

   Vue.component('example2',{template:'#example2'})

   var vm = new Vue({

     el: '#content',

     data: {

       compontentName :'example1',

       cur:0

       }

   });


```


全代码:


```html

<!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>


```



屏幕截图 2021-11-05 154647.png屏幕截图 2021-11-05 154700.png

目录
相关文章
|
1月前
|
JavaScript
Vue中如何实现兄弟组件之间的通信
在Vue中,兄弟组件可通过父组件中转、事件总线、Vuex/Pinia或provide/inject实现通信。小型项目推荐父组件中转或事件总线,大型项目建议使用Pinia等状态管理工具,确保数据流清晰可控,避免内存泄漏。
224 2
|
7天前
|
缓存 JavaScript
vue中的keep-alive问题(2)
vue中的keep-alive问题(2)
214 137
|
4月前
|
人工智能 JavaScript 算法
Vue 中 key 属性的深入解析:改变 key 导致组件销毁与重建
Vue 中 key 属性的深入解析:改变 key 导致组件销毁与重建
655 0
|
4月前
|
JavaScript UED
用组件懒加载优化Vue应用性能
用组件懒加载优化Vue应用性能
|
3月前
|
JavaScript 安全
在 Vue 中,如何在回调函数中正确使用 this?
在 Vue 中,如何在回调函数中正确使用 this?
160 0
|
3月前
|
人工智能 JSON JavaScript
VTJ.PRO 首发 MasterGo 设计智能识别引擎,秒级生成 Vue 代码
VTJ.PRO发布「AI MasterGo设计稿识别引擎」,成为全球首个支持解析MasterGo原生JSON文件并自动生成Vue组件的AI工具。通过双引擎架构,实现设计到代码全流程自动化,效率提升300%,助力企业降本增效,引领“设计即生产”新时代。
316 1
|
4月前
|
JavaScript 前端开发 UED
Vue 表情包输入组件实现代码及详细开发流程解析
这是一篇关于 Vue 表情包输入组件的使用方法与封装指南的文章。通过安装依赖、全局注册和局部使用,可以快速集成表情包功能到 Vue 项目中。文章还详细介绍了组件的封装实现、高级配置(如自定义表情列表、主题定制、动画效果和懒加载)以及完整集成示例。开发者可根据需求扩展功能,例如 GIF 搜索或自定义表情上传,提升用户体验。资源链接提供进一步学习材料。
238 1
|
6月前
|
JavaScript
vue实现任务周期cron表达式选择组件
vue实现任务周期cron表达式选择组件
888 4
|
5月前
|
JavaScript 数据可视化 前端开发
基于 Vue 与 D3 的可拖拽拓扑图技术方案及应用案例解析
本文介绍了基于Vue和D3实现可拖拽拓扑图的技术方案与应用实例。通过Vue构建用户界面和交互逻辑,结合D3强大的数据可视化能力,实现了力导向布局、节点拖拽、交互事件等功能。文章详细讲解了数据模型设计、拖拽功能实现、组件封装及高级扩展(如节点类型定制、连接样式优化等),并提供了性能优化方案以应对大数据量场景。最终,展示了基础网络拓扑、实时更新拓扑等应用实例,为开发者提供了一套完整的实现思路和实践经验。
653 77
|
6月前
|
缓存 JavaScript 前端开发
Vue 基础语法介绍
Vue 基础语法介绍