金狮镖局 Design By www.egabc.com
这篇文章主要介绍了微信小程序登录时如何获取input框中的内容,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
最近写小程序项目遇到一些问题,今天整理下这些问题的解决方法,希望对用户有帮助。下面是登录页,点击登录时获取input框中的值,
效果如下:
wxml布局如下:
<view > <input type="text" placeholder-style="color:#fff;" bindinput="userNameInp" placeholder="请输入账号" /> </view> <view > <input password placeholder-style="color:#fff;" bindinput="usePasswordInp" placeholder="请输入密码"/> </view> <button class="loginBtn" bindtap='loginFn'>登录</button>
js代码如下:
const app = getApp(); Page({ /** * 页面的初始数据 */ data: { userName: "", passWord: "", }, //监听输入的账号 userNameInp: function (e) { this.data.userName = e.detail.value; }, //监听输入的密码 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' // 默认值 }, 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: '服务器出现错误', icon: 'none', duration: 2000 }) } }) } }, //跳转到忘记密码页面 onTapDayWeather() { wx.navigateTo({ url: '/pages/updatepwd/updatepwd', }) }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { }, })
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
金狮镖局 Design By www.egabc.com
金狮镖局
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
金狮镖局 Design By www.egabc.com
暂无微信小程序登录时如何获取input框中的内容的评论...
更新日志
2024年09月23日
2024年09月23日
- 梁汉文2008-EDMONDHITS48[香港]3CD[WAV+CUE]
- 国风大师纯音系列《童丽-[渭城曲]》1CD[WAV分轨][593.5MB]
- 国风大师纯音系列《许菱子《烧筝2》古筝曲集》1CD[WAV分轨][1.3GB]
- 王子异《1996 Part.2》[320K/MP3][18.29MB]
- 群星.1994-宝丽金最倾情3CD【宝丽金】【WAV+CUE】
- 乐俊亨.2024-同泪【CharioticMusic】【FLAC分轨】
- 何耀珊.2006-收获【华纳】【WAV+CUE】
- 梁汉文1994-壹精选[华星][WAV+CUE]
- 洪荣宏1981-歹路不可行·相思雨(飞跃复刻版)[光美][WAV+CUE]
- 旅行团2015-10Day’s[来福胶泥][WAV+CUE]
- 龙千玉.2011-卡将哟【豪记】【WAV+CUE】
- 蔣志光.1993-多情多寂寞(国专)【BMG】【WAV+CUE】
- 陈慧娴.1996-雪映美白96演唱会2CD(2024环球红馆40复刻系列)【环球】【WAV+CUE】
- 王子异《1996 Part.2》[FLAC/分轨][50.66MB]
- 贵族音乐《古典名曲与轻音乐钢琴 打开宝宝睡眠开关》[320K/MP3][155.91MB]