忘记密码
当前位置:   article > 正文

uniapp登陆页面功能_uniapp功能页面

uniapp功能页面

首先是布局

  1. <template>
  2. <view>
  3. <view class="d-flex a-center j-sb py-2 px-3 text-light-muted">
  4. <view class="iconfont icon-shanchu1" ></view>
  5. <view class="font-md" >忘记密码</view>
  6. </view>
  7. <view class="p-5">
  8. <view class="font-big mb-5">密码登录</view>
  9. <input type="text" class="border-bottom mb-4 uni-input px-0"
  10. placeholder="请输入手机号/邮箱/账号" v-model="username"
  11. placeholder-class="text-light-muted"
  12. />
  13. <input type="text" class="border-bottom mb-4 uni-input px-0"
  14. placeholder="请输入密码" v-model="password"
  15. placeholder-class="text-light-muted"/>
  16. <view class="py-2 w-100 d-flex a-center j-center main-bg-color text-white rounded font-md mb-4" hover-class="main-bg-hover-color" >
  17. 登录
  18. </view>
  19. <label class="checkbox d-flex a-center" >
  20. <checkbox :checked="check"/>
  21. <text class="text-light-muted font">已阅读并同意XXXXX协议</text>
  22. </label>
  23. </view>
  24. </view>
  25. </template>

 

获取登陆数据用post请求:

 在login页面中引入

import {getLogin} from '../../utils/login.js'

之后获取接口

  1. getLogin(this.username,this.password).then(res=>{
  2. console.log(res);
  3. })

写一个正则

  1. rules: {
  2. username: [{
  3. rule: /^[a-zA-Z]\w{4,17}$/,
  4. msg: "账号必须字母开头,长度在5~18之间,只能包含字母、数字和下划线"
  5. }
  6. ],
  7. password: [{
  8. rule: /^.{5,20}$/,
  9. msg: "密码长度必须为5-20个字符"
  10. }]
  11. },
  1. methods: {
  2. // 回退到四个tabbar中的我的页面,使用uni.switchTab
  3. goBack() {
  4. uni.switchTab({
  5. url: '../myfile/myfile'
  6. })
  7. },
  8. // 忘记密码
  9. forget() {
  10. console.log('忘记密码');
  11. },
  12. // 写个函数用来判断复选框是否勾选并提示
  13. validate(key) {
  14. var check = true;
  15. this.rules[key].forEach(v => {
  16. // uni-app 判断输入是否符合要求
  17. if (!v.rule.test(this[key])) {
  18. uni.showToast({
  19. title: v.msg,
  20. // 勾号消失
  21. icon: 'none'
  22. })
  23. return check = false
  24. }
  25. })
  26. return check
  27. },
  28. // 点击登陆按钮
  29. submit() {
  30. if (!this.check) {
  31. return uni.showToast({
  32. title: '请先同意协议',
  33. icon: 'none'
  34. })
  35. }
  36. if (!this.validate('username')) return;
  37. if (!this.validate('password')) return;
  38. getLogin(this.username, this.password).then(res => {
  39. console.log(res);
  40. uni.switchTab({
  41. url: '../myfile/myfile'
  42. })
  43. })
  44. },
  45. }

即可实现功能

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/花生_TL007/article/detail/367678
推荐阅读
相关标签