1. 程式人生 > 其它 >微信小程式 登入註冊

微信小程式 登入註冊

技術標籤:微信小程式

文章目錄

1. source code

<form bindsubmit="handleSubmit" wx:if="{{ onoff }}">
   使用者名稱: <input type="text" name='username'/>
   密碼: <input type="password" name='password'/>
   手機號: <input type="text"
name='phone'/>
<button form-type="submit"> 註冊 </button> </form> <form bindsubmit="handleLogin" wx:else> 使用者名稱: <input type="text" name='username'/> 密碼: <input type="password" name='password'/> <button form-type
="submit">
登入 </button> </form>
// pages/login/login.js
Page({

  /**
   * 頁面的初始資料
   */
  data: {
      onoff: false
  },
  handleSubmit(e){
    const {value} = e.detail;
    // console.log(value)
    const that = this;
    wx.request({
      url: 'http://pddapi.h5sm.com/index/pdduser/getpddregister'
, method: 'post', data: value, success(res){ if(res.data.status == 1){ that.setData({ onoff: false }) } } }) }, handleLogin(e){ const {username, password} = e.detail.value; const that = this; wx.request({ url: 'http://pddapi.h5sm.com/index/pdduser/getpddlogin', method: 'post', data:{ username, password }, success(res){ console.log(res) } }) }, /** * 生命週期函式--監聽頁面載入 */ onLoad: function (options) { }, /** * 生命週期函式--監聽頁面初次渲染完成 */ onReady: function () { }, /** * 生命週期函式--監聽頁面顯示 */ onShow: function () { }, /** * 生命週期函式--監聽頁面隱藏 */ onHide: function () { }, /** * 生命週期函式--監聽頁面解除安裝 */ onUnload: function () { }, /** * 頁面相關事件處理函式--監聽使用者下拉動作 */ onPullDownRefresh: function () { }, /** * 頁面上拉觸底事件的處理函式 */ onReachBottom: function () { }, /** * 使用者點選右上角分享 */ onShareAppMessage: function () { } })

在這裡插入圖片描述