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

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;
}

欢迎欣赏。

相关推荐
CRMEB系统商城25 分钟前
前后端技术栈全面换代!CRMEB 多商户(Java)v3.0更新预告
java·开发语言·小程序·php
醒目802 小时前
从图像到拼豆图纸:像素化生成与色板匹配技术实践
微信小程序
2501_916007473 小时前
苹果应用商店App Store上架费用标准及原因解析
android·ios·小程序·https·uni-app·iphone·webview
00后程序员张21 小时前
苹果App Store上架指南:费用、原理与步骤详解
android·ios·小程序·https·uni-app·iphone·webview
paopaokaka_luck1 天前
个人综合管理小程序(echarts数据看板、健康数据记录与趋势查看、目标拆解和进度管理、日程待办与番茄钟、习惯打卡、收支统计、个人生活记录、跨模块智能提醒)
前端·javascript·spring·小程序·数据分析·echarts·生活
愚公搬代码1 天前
【愚公系列】《微信小程序项目实战(AI编程+视频图解)》002-一张新地图:AI创业的核心分析框架
人工智能·微信小程序·ai编程
m0_587383002 天前
广州24小时自助健身房解决方案实战指南与系统部署要点
java·spring·小程序·架构·需求分析
ZeroNews内网穿透2 天前
企业内网穿透别再用随机域名!自有域名实现 OA/ERP 公网安全访问
微信小程序·内网穿透·erp·zeronews·运维实战·企业oa·自有域名
m0_587383002 天前
西安同城拼车软件开发实战指南:从零搭建高效系统
人工智能·小程序·数据挖掘·系统架构·需求分析
weixin_lynhgworld2 天前
抽取类盲盒小程序的五条合规红线意味着什么?
小程序