微信小程序实现登录注册

微信小程序实现登录注册

1. 新建工程

项目名称自定义命名,目录自己选择,AppID可以使用注册号,或者去微信公众平台申请一个AppID,开发模式选择小程序后端服务选择不使用云开发模板选择JavaScript-基础模板

在这里插入图片描述

2. 编写WXML文件

删除index.wxml文件中的内容,将以下代码复制到index.wxml中

<view class="container-view">
  <view class="header">
    <text>登录/注册</text>
  </view>
  <view class="tip">
    <text>请输入账号</text>
  </view>
  <view class="input">
    <!-- model:value用于双向绑定,组件中的值发生变化,js中的值也会变化,js中的值发生变化,组件中的值也会变化 -->
    <input type="text" class="account-input" placeholder="请输入账号" model:value="{{account}}" bindinput="accountInput"/>
  </view>
  <view class="input">
    <!-- bindinput键盘输入时,触发的回调 -->
    <input type="password" class="account-input" placeholder="请输入密码" model:value="{{password}}" bindinput="passwordInput"/>
  </view>
  <view class="checkbox">
    <checkbox model:checked="{{checked}}"/>
    <text class="normal">登录/注册即表示同意</text>
    <text class="highlight" bindtap="nav1">《隐私协议》</text>
    <text class="normal"></text>
    <text class="highlight" bindtap="nav2">《服务协议》</text>
  </view>
  <view class="button-view">
    <button type="primary" style="width: 100%;" disabled="{{account.length == 0 || password.length == 0 || !checked}}" bindtap="confirm">确认</button>
  </view>
  <view class="footer">
    <text>微信小程序登录注册</text>
  </view>
</view>

3. 编写WXSS文件

.header {
  font-size: 50rpx;
  margin-top: 30rpx;
  margin-left: 40rpx;
  font-weight: bold;
}

.tip {
  margin-left: 40rpx;
  margin-top: 20rpx;
  font-size: 26rpx;
  color: #515151;
}

.input {
  margin-left: 40rpx;
  width: calc(100% - 80rpx);
  margin-top: 40rpx;
}

.account-input {
  border-bottom: #919191 solid 2rpx;
  height: 80rpx;
}

.checkbox {
  margin-left: 30rpx;
  margin-top: 20rpx;
}

.checkbox checkbox {
  transform: scale(0.7, 0.7);
}

.normal {
  font-size: 24rpx;
}

.highlight {
  font-size: 24rpx;
  color: cornflowerblue;
}

.button-view {
  margin-top: 100rpx;
  margin-left: 40rpx;
  width: calc(100% - 80rpx);
}

.footer {
  position: absolute;
  bottom: 40rpx;
  text-align: center;
  width: 100%;
  font-size: 28rpx;
  color: gray;
}

4. 编写js文件

// index.js
// 获取应用实例
const app = getApp()

Page({
  data: {
    account: "",
    password: "",
    checked: false,
  },

  confirm() {
    // 弹出提示框
    wx.showModal({
      title: '进行登录/注册',
      content: `account: ${this.data.account} password: ${this.data.password}`,
    });
  },

  nav1() {
    // 弹出确认框
    wx.showToast({
      title: '跳转隐私协议',
    });
  },

  nav2() {
    wx.showToast({
      title: '跳转用户协议',
    });
  },

  accountInput() {
    console.log(this.data.account);
  },

  passwordInput() {},

  onLoad() {
    
  },
})

5. 效果图

在这里插入图片描述

  • 2
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

天天向上Charles

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值