开始

账号密码登陆和手机登陆的切换功能
image.png
用template包裹起来
image.png

  1. <!-- 账号密码登陆 -->
  2. <template>
  3. </template>

声明属性值来判断
image.png

  1. status:0, // 0代表账号密码登陆, 1手机验证码登陆

登陆状态的切换
image.png
状态切换事件
image.png
改成true或false的形式
image.png

  1. <!-- 登陆状态切换 -->
  2. <view class="login-status u-f-ajc login-padding"
  3. @tap="changeStatus">
  4. {{status?'账号密码登陆':'验证码登陆'}}<view class="icon iconfont icon-jinru"></view>
  5. </view>
  1. status:false, // false代表账号密码登陆, true手机验证码登陆

替换事件这里直接取反就可以了。
image.png

  1. // 切换登陆状态
  2. changeStatus(){
  3. this.status=!this.status;
  4. },

image.png
手机密码登陆
image.png

点击
image.png

image.png
下面。实现输入复制,登陆按钮 变色。
image.png

本节代码

login.vue页面

  1. <template>
  2. <view>
  3. <!-- 状态栏 -->
  4. <!-- <uni-status-bar></uni-status-bar> -->
  5. <uni-nav-bar background-color="#FFE933" status-bar />
  6. <!-- 关闭按钮 -->
  7. <view class="icon iconfont icon-guanbi" @tap="back"></view>
  8. <!-- 引入背景图 -->
  9. <image class="loginhead" src="../../static/common/loginhead.png" mode="widthFix" lazy-load></image>
  10. <view class="body">
  11. <!-- 账号密码登陆 -->
  12. <template v-if="!status">
  13. <view class="login-input-box">
  14. <view class="phone u-f-ajc">+86</view>
  15. <input type="text" class="uni-input common-input phone-input" placeholder="昵称/手机号/邮箱" />
  16. </view>
  17. <view class="login-input-box">
  18. <view class="login-input-box">
  19. <input type="text" class="uni-input common-input forget-input" placeholder="请输入密码" />
  20. <view class="forget u-f-ajc login-font-color">忘记密码</view>
  21. </view>
  22. </view>
  23. </template>
  24. <template v-else>
  25. <view class="login-input-box">
  26. <view class="phone u-f-ajc">+86</view>
  27. <input type="text" class="uni-input common-input phone-input" placeholder="手机号" />
  28. </view>
  29. <view class="login-input-box">
  30. <input type="text" class="uni-input common-input forget-input" placeholder="验证码" />
  31. <view class="forget u-f-ajc login-font-color yanzhengma">
  32. <view class="u-f-ajc">
  33. 获取验证码
  34. </view>
  35. </view>
  36. </view>
  37. </template>
  38. <button class="user-set-btn" :class="{'user-set-btn-disable':disabled}" :loading="loading" @tap="submit"
  39. type="primary" :disabled="disabled">登陆</button>
  40. </view>
  41. <!-- 登陆状态切换 -->
  42. <view class="login-status u-f-ajc login-padding" @tap="changeStatus">
  43. {{status?'账号密码登陆':'验证码登陆'}}
  44. <view class="icon iconfont icon-jinru"></view>
  45. </view>
  46. <!-- 第三方登陆 -->
  47. <view class="other-login-title u-f-ajc login-padding">第三方登陆</view>
  48. <other-login></other-login>
  49. <!-- 协议 -->
  50. <view class="login-rule u-f-ajc login-padding login-font-color">
  51. 注册即代表您同意<view class="login-font-color">《XXXX协议》</view>
  52. </view>
  53. </view>
  54. </template>
  55. <script>
  56. import otherLogin from '@/components/home/other-login.vue';
  57. export default {
  58. components: {
  59. otherLogin
  60. },
  61. data() {
  62. return {
  63. status: false, // false代表账号密码登陆, true手机验证码登陆
  64. disabled: true,
  65. loading: false
  66. }
  67. },
  68. methods: {
  69. // 切换登陆状态
  70. changeStatus() {
  71. this.status = !this.status;
  72. },
  73. back() {
  74. console.log('返回上一步');
  75. },
  76. submit() {
  77. console.log('提交登陆');
  78. }
  79. }
  80. }
  81. </script>
  82. <style>
  83. @import url('@/common/form.css');
  84. .login-padding {
  85. padding: 20upx;
  86. }
  87. .login-font-color {
  88. color: #BBBBBB;
  89. }
  90. .loginhead {
  91. width: 100%;
  92. margin-top: -5upx;
  93. }
  94. .icon-guanbi {
  95. position: fixed;
  96. top: 60upx;
  97. left: 30upx;
  98. font-size: 40upx;
  99. font-weight: bold;
  100. color: #332F0A;
  101. z-index: 100;
  102. }
  103. .other-login-title {
  104. position: relative;
  105. }
  106. .other-login-title::before,
  107. .other-login-title::after {
  108. content: '';
  109. position: absolute;
  110. background: #CCCCCC;
  111. height: 1upx;
  112. width: 100upx;
  113. top: 50%;
  114. }
  115. .other-login-title::before {
  116. left: 25%;
  117. }
  118. .other-login-title::after {
  119. right: 25%;
  120. }
  121. .login-input-box {
  122. position: relative;
  123. }
  124. .login-input-box .forget-input {
  125. padding-right: 150upx;
  126. }
  127. .login-input-box .forget {
  128. position: absolute;
  129. right: 0;
  130. top: 0;
  131. height: 100%;
  132. width: 150upx;
  133. /* background: yellow; */
  134. z-index: 100;
  135. }
  136. .login-input-box .phone {
  137. position: absolute;
  138. left: 0;
  139. top: 0;
  140. height: 100%;
  141. width: 100upx;
  142. z-index: 100;
  143. font-weight: bold;
  144. }
  145. .login-input-box .phone-input {
  146. padding-left: 100upx;
  147. }
  148. .yanzhengma view {
  149. background: #EEEEEE;
  150. border-radius: 10upx;
  151. font-size: 25upx;
  152. width: 150upx;
  153. padding: 10upx 0;
  154. }
  155. </style>

结束