微信小程序登录时如何获取input框中的内容
网络编程 2021-07-04 15:02www.168986.cn编程入门
这篇文章主要介绍了微信小程序登录时如何获取input框中的内容,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
这篇文章主要介绍了微信小程序登录时如何获取input框中的内容,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
最近写小程序项目遇到一些问题,今天整理下这些问题的解决方法,希望对用户有帮助。狼蚁网站SEO优化是登录页,点击登录时获取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--form-urlencoded' // 默认值 }, method: 'post', suess: function (res) { wx.hideLoading(); wx.removeStorageSync('sessionid'); // console.log('登录成功', res.data.data); if (res.data.code == "0000") { wx.showToast({ title: '登录成功', icon: 'suess', 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) { }, })
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持狼蚁SEO。
上一篇:基于javascript实现贪吃蛇经典小游戏
下一篇:微信小程序日历插件代码实例
编程语言
- 机械手焊接机器人编程 机械手焊接设备编程
- vb数据库编程实例,vb做数据库
- tiobe世界编程语言排行榜,全球编程语言排行
- 成都java编程培训 成都it编程培训中心
- 编程基础培训,编程基础知识培训
- flash游戏编程基础教程,flash游戏开发教程
- 不会英语能学编程吗 不会英语可以学程序员吗
- 爱心代码编程C语言 爱心代码编程c语言公式
- c语言编程学习入门 c语言编程快速入门
- 西门子plc编程培训 西门子plc编程培训班
- 哪里可以学编程 台州哪里可以学编程
- 少儿编程哪个好 少儿编程哪个品牌好
- 编程是什么意思,图形编程是什么意思
- c语言编程软件下载,c语言编程软件在哪下载
- java编程软件下载,java编程下载手机版
- ug编程培训学校,ug编程培训教程