溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

小程序登錄界面怎么開發(fā)

發(fā)布時(shí)間:2022-03-09 10:03:36 來源:億速云 閱讀:129 作者:iii 欄目:開發(fā)技術(shù)

這篇“小程序登錄界面怎么開發(fā)”文章的知識(shí)點(diǎn)大部分人都不太理解,所以小編給大家總結(jié)了以下內(nèi)容,內(nèi)容詳細(xì),步驟清晰,具有一定的借鑒價(jià)值,希望大家閱讀完這篇文章能有所收獲,下面我們一起來看看這篇“小程序登錄界面怎么開發(fā)”文章吧。

  小程序登錄界面怎么開發(fā)

小程序登錄界面樣式開發(fā)實(shí)例:

  index.wxml

<view class="container">

  <view class="usermotto">

    <text class="user-motto">{{motto}}</text>

    用戶名:

    <input type="text" bindinput="userNameInput"/>

    密碼:

    <input type="text" bindinput="userPasswordInput" password="true"/>

    <button bindtap="logIn">登錄</button>

  </view>

</view>

  index.js

var app = getApp()

Page({

  data: {

    motto: '歡迎登錄WXapp',

    userName:'',

    userPassword:'',

    id_token:'',//方便存在本地的locakStorage

    response:'' //存取返回?cái)?shù)據(jù)

  },

  userNameInput:function(e){

    this.setData({

      userName: e.detail.value

    })

  },

  userPasswordInput:function(e){

    this.setData({

      userPassword: e.detail.value

    })

    console.log(e.detail.value)

  },

  logIn:function(){

    var that = this

    wx.request({

      url: 'http://localhost:8000/admin',

      data: {

        username: this.data.userName,

        password: this.data.userPassword,

      },

      method: 'GET',

      success: function (res) {

        that.setData({

          id_token: res.data.id_token,

          response:res

        })

        try {

          wx.setStorageSync('id_token', res.data.id_token)

        } catch (e) {

        }

        wx.navigateTo({

          url: '../components/welcome/welcome'

        })

        console.log(res.data);

      },

      fail: function (res) {

        console.log(res.data);

        console.log('is failed')

      }

    })

  }

})

  js文件里Page里的data就類似與react中的state的機(jī)制,

  之后在js文件中想要調(diào)用data里的數(shù)據(jù)就必須才才用this.data.XXX;

  但是在wxml中想要綁定data里的數(shù)據(jù),就才用雙括號(hào)的方法,而且!不需要!this.data。直接就是{{XXX}}。

  在回到代碼里看,wxml中主要就是兩個(gè)input框和一個(gè)button。通過小程序input的原生API - bindInput (文檔:小程序input),就可以獲取input的值,

  然后在data里定義兩個(gè)(userName和userPassword)來存取這兩個(gè)input的輸入值。

  再通過button的 bindTap綁定js文件中的logIn函數(shù)。

  在logIn函數(shù)中,就通過this.data.userName和this.data.userPassword來獲取曾經(jīng)輸入的兩個(gè)值。

  在通過調(diào)用微信的發(fā)送請求API,把兩個(gè)值放在請求中,這就有點(diǎn)像ajax發(fā)送請求了。

  再在success中寫下成功之后想要做的事情,比如這個(gè)例子里,就跳轉(zhuǎn)到welcome頁面。

以上就是關(guān)于“小程序登錄界面怎么開發(fā)”這篇文章的內(nèi)容,相信大家都有了一定的了解,希望小編分享的內(nèi)容對大家有幫助,若想了解更多相關(guān)的知識(shí)內(nèi)容,請關(guān)注億速云行業(yè)資訊頻道。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI