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

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

欢迎欣赏。

相关推荐
weishuangyun1239 小时前
微信小程序怎么选公司?上线流程详解
大数据·小程序
show43318 小时前
2026微信小程序视频转文字多语种识别引擎技术选型:22种方言25种外语挑战
微信小程序·小程序·音视频
lhldsg1 天前
县城外卖系统开发实战:从需求分析到上线全流程指南
java·小程序·需求分析
Kingexpand_com1 天前
旅游小程序怎么选型?模板与定制二次开发技术对比解析
小程序·旅游·小程序开发·旅行·定制开发
万岳科技系统开发1 天前
外卖跑腿小程序如何提升本地生活服务平台运营效率?
大数据·小程序·生活
MrFlySand_飞沙1 天前
uniapp开发微信小程序实现接入企业微信客服
微信小程序·小程序·uni-app·企业微信
码艺-Alimjan1 天前
JWT 的本质、误区与正确落地:一套不依赖任何框架的架构方法论-微信小程序代码案例-Api 安全性拉满
微信小程序·架构·notepad++
禁止摆烂_才浅1 天前
微信小程序高频面试题
前端·面试·微信小程序
Ai-_Man1 天前
豆包智能体把对话批量导出为Word或PDF的正确顺序
人工智能·ai·小程序·pdf·word
mykj15511 天前
打车顺风车代驾小程序的核心,远不止一个页面
小程序·代驾小程序开发·顺风车小程序·出租车app