微信小程序--动态切换登录注册标签页

1、try.js的

1.1、data函数

添加

复制代码
activeTab: 'login', // 当前激活的标签,默认为登录

1.2、添加一个函数

复制代码
// 切换登录/注册标签
  switchTab(e) {
    const tab = e.currentTarget.dataset.tab;
    this.setData({
      activeTab: tab
    });
  },

2、try.wxml的代码

复制代码
<!--pages/try/try.wxml-->
<view class="login-container">
  <view class="header">
    <text class="logo">DataDevices</text>
    <text class="slogan">智能设备管理平台</text>
  </view>

  <view class="form-container">
    <view class="tab-container">
      <text class="tab-item {{activeTab === 'login' ? 'active' : ''}}" bindtap="switchTab" data-tab="login">登录</text>
      <text class="tab-item {{activeTab === 'register' ? 'active' : ''}}" bindtap="switchTab" data-tab="register">注册</text>
    </view>
  </view>
  
  <!-- 登录表单 -->
  <view wx:if="{{activeTab === 'login'}}" class="form">
  <view>登录表单</view>
  </view>

  <!-- 注册表单 -->
  <view wx:if="{{activeTab === 'register'}}" class="form">
  <view>注册表单</view>
  </view>

</view>

3、try.wxss

复制代码
/* pages/try/try.wxss */
.login-container {
  padding: 40rpx;
  background-color: #f5f5f5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
.header {
  text-align: center;
  margin-top: 100rpx;
  margin-bottom: 60rpx;
}
.logo {
  font-size: 48rpx;
  font-weight: bold;
  color: #1890ff;
  display: block;
  margin-bottom: 10rpx;
}
.slogan {
  font-size: 24rpx;
  color: #666;
}
.form-container {
  background-color: white;
  border-radius: 12rpx;
  padding: 40rpx;
  box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.05);
  margin-bottom: 40rpx;
}
.tab-container {
  display: flex;
  border-bottom: 1rpx solid #e5e5e5;
  margin-bottom: 40rpx;
}
.tab-item {
  flex: 1;
  text-align: center;
  font-size: 32rpx;
  padding: 20rpx 0;
  color: #666;
  position: relative;
}
.tab-item.active {
  color: #1890ff;
  font-weight: bold;
}
/* 给"当前选中的 tab"底部加一条蓝色横线 */
.tab-item.active::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 25%;
  width: 50%;
  height: 4rpx;
  background-color: #1890ff;
}

欢迎欣赏。

相关推荐
社会渣渣6 小时前
开发者工具正常、真机白屏:一次渲染差异排查
微信小程序
daguanren9 小时前
一个页面外壳,多页复用:weapp-vite / Wevu 布局的编译与动态切换
微信小程序
源码手记9 小时前
基于微信小程序的上门代厨厨师预约系统-毕设源码
微信小程序·小程序·课程设计
微订校园外卖系统9 小时前
自建自营小程序落地前,先把订单状态机与试单链路跑通
小程序·外卖系统·本地生活·微订
千寻技术帮10 小时前
基于微信小程序的点餐管理系统_50044(源码+脚本+文档)
mysql·微信小程序·小程序·毕业设计·springboot·点餐管理系统
AI源码11 小时前
中医药文化介绍小程序
小程序·notepad++
千寻技术帮1 天前
基于微信小程序的零食销售系统(源码+文档+脚本)50047
数据库·mysql·微信小程序·小程序·毕业设计·springboot·课程设计
源码手记1 天前
基于微信小程序的驾考刷题学习系统-毕设源码
学习·微信小程序·课程设计
lyz2468591 天前
uniapp-x在小程序使用uchart图表加载问题
小程序·uni-app
AI源码1 天前
心理健康教育小程序
小程序