新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
微信小程序登錄時如何獲取input框中的內(nèi)容
這篇文章主要介紹了微信小程序登錄時如何獲取input框中的內(nèi)容,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下
網(wǎng)站建設(shè)公司,為您提供網(wǎng)站建設(shè),網(wǎng)站制作,網(wǎng)頁設(shè)計(jì)及定制網(wǎng)站建設(shè)服務(wù),專注于企業(yè)網(wǎng)站制作,高端網(wǎng)頁制作,對活動板房等多個行業(yè)擁有豐富的網(wǎng)站建設(shè)經(jīng)驗(yàn)的網(wǎng)站建設(shè)公司。專業(yè)網(wǎng)站設(shè)計(jì),網(wǎng)站優(yōu)化推廣哪家好,專業(yè)網(wǎng)站推廣優(yōu)化,H5建站,響應(yīng)式網(wǎng)站。
最近寫小程序項(xiàng)目遇到一些問題,今天整理下這些問題的解決方法,希望對用戶有幫助。下面是登錄頁,點(diǎn)擊登錄時獲取input框中的值,
效果如下:
wxml布局如下:
js代碼如下:
const app = getApp(); Page({ /** * 頁面的初始數(shù)據(jù) */ data: { userName: "", passWord: "", }, //監(jiān)聽輸入的賬號 userNameInp: function (e) { this.data.userName = e.detail.value; }, //監(jiān)聽輸入的密碼 usePasswordInp: function (e) { this.data.passWord = e.detail.value; }, //登錄 loginFn: function () { var that = this; if (that.data.userName.length == 0 || that.data.passWord.length == 0) { wx.showToast({ title: '賬號或密碼為空', icon: 'loading', duration: 2000 }) } else { wx.showLoading({ title: '登錄中...', }) wx.request({ url: 'https://localhost:8180/exam/login', data: { username: that.data.userName, password: that.data.passWord }, header: { 'content-type': 'application/x-www-form-urlencoded' // 默認(rèn)值 }, method: 'post', success: function (res) { wx.hideLoading(); wx.removeStorageSync('sessionid'); // console.log('登錄成功', res.data.data); if (res.data.code == "0000") { wx.showToast({ title: '登錄成功', icon: 'success', duration: 1000 }) wx.setStorageSync('sessionid', res.header['Set-Cookie']); //保存Cookie到Storage wx.setStorage({ key: 'myData', data: res.data.data }) wx.redirectTo({ url: '/pages/index/index', }) } else { wx.showToast({ title: '登錄失敗', icon: 'none', duration: 2000 }) } }, fail: function (e) { wx.showToast({ title: '
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持創(chuàng)新互聯(lián)。
網(wǎng)站標(biāo)題:微信小程序登錄時如何獲取input框中的內(nèi)容
鏈接URL:http://fisionsoft.com.cn/article/iehghs.html