微信小程序如何实现登录页面

发布时间:2022-05-23 09:34:15 作者:iii
来源:亿速云 阅读:1208

这篇文章主要讲解了“微信小程序如何实现登录页面”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“微信小程序如何实现登录页面”吧!

1. 在首页中加入一个弹窗作为登录窗口,效果如下图:

微信小程序如何实现登录页面

(1)index.wxml

登录窗口代码如下:

<view class="modal-mask" bindtap="hideModal" catchtouchmove="preventTouchMove" wx:if="{{!hiddenmodalput}}"></view>
<view class="modal-dialog" wx:if="{{!hiddenmodalput}}" catchtouchmove="preventTouchMove">
  <view class="modal-title">{{tip}}</view>
  <view class="modal-content">
    <view class="modal-input">
      <input placeholder-class="input-holder" type="text" maxlength="20" bindinput="inputUsername" class="input" placeholder="用户名" value="{{username}}">
      </input>
    </view>
    <view class="modal-input">
      <input placeholder-class="input-holder" type="text" maxlength="20" bindinput="inputPassword" class="input" placeholder="密码" value="{{password}}">
      </input>
    </view>
  </view>
  <view class="modal-footer">
    <navigator class="btn-cancel" target="miniProgram" open-type="exit">
      退出
    </navigator>
    <!-- <view class="btn-cancel" bindtap="cancel" data-status="cancel">取消</view> -->
    <view class="btn-confirm" bindtap="confirm" data-status="confirm">确定</view>
  </view>
</view>

(2)index.js

在onload方法中判断当前的登录状态,这里我用了简单的 getStorage 来保存登录信息,hiddenmodalput控制登录窗口是否显示,这样就可以实现简单的登录页面,hideTabBar是用来隐藏底部tab栏按键。

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that = this;
    wx.getStorage({
      key: 'username',
      success (res) {
        console.log(res.data);
        that.setData({
          hiddenmodalput:true,
        })
      },
      fail (res) {
        console.log(res);
        that.setData({
          hiddenmodalput:false,
        })
        wx.hideTabBar({
          animation: true,
          success: (res) => {},
          fail: (res) => {},
          complete: (res) => {},
        })
      }
    })
  },

2.新建一个登录页面

(1)在首页onload中进行登录转态验证,如果为未登录状态,则可以使用wx.navigateTo跳转到登录页面

(2)在登录页面中处理登录的相关逻辑,也可以实现相同的效果。

感谢各位的阅读,以上就是“微信小程序如何实现登录页面”的内容了,经过本文的学习后,相信大家对微信小程序如何实现登录页面这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是亿速云,小编将为大家推送更多相关知识点的文章,欢迎关注!

推荐阅读:
  1. 微信小程序如何实现滑动
  2. 微信小程序如何实现tabBar

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

微信小程序

上一篇:Python如何实现五子棋人机对战和人人对战

下一篇:微信小程序如何实现下拉筛选功能

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》