开始

首先是获取这3个文本框的值
image.png

image.png

  1. return {
  2. oldpassword:'',
  3. newpassword:'',
  4. renewpassword:''
  5. }

双向绑定
image.png

  1. <view class="body">
  2. <input type="text" v-model="oldpassword"
  3. class="uni-input common-input"
  4. placeholder="输入旧密码" />
  5. <input type="text" v-model="newpassword"
  6. class="uni-input common-input"
  7. placeholder="输入新密码" />
  8. <input type="text" v-model="renewpassword"
  9. class="uni-input common-input"
  10. placeholder="输入确认密码" />
  11. <button class="user-set-btn user-set-btn-disable" type="primary">完成</button>
  12. </view>

点击事件
image.png

  1. <button class="user-set-btn user-set-btn-disable"
  2. @tap="submit"
  3. type="primary">完成</button>

image.png

  1. methods: {
  2. // 验证层
  3. check(){
  4. },
  5. // 提交
  6. submit(){
  7. }
  8. }

image.png

image.png

image.png

image.png

image.png
最后return true
image.png

  1. if(!this.oldpassword || this.oldpassword==""){
  2. uni.showToast({
  3. title: '旧密码不能为空',
  4. icon:"none"
  5. });
  6. return false;
  7. }
  8. if(!this.newpassword || this.newpassword==""){
  9. uni.showToast({
  10. title: '新密码不能为空',
  11. icon:"none"
  12. });
  13. return false;
  14. }
  15. if(!this.renewpassword || this.renewpassword==""){
  16. uni.showToast({
  17. title: '确认密码不能为空',
  18. icon:"none"
  19. });
  20. return false;
  21. }
  22. if(this.newpassword !== this.renewpassword){
  23. uni.showToast({
  24. title: '确认密码和新密码不一致',
  25. icon:"none"
  26. });
  27. return false;
  28. }
  29. return true;

image.png

  1. // 提交
  2. submit() {
  3. if(!this.check()){return;}
  4. uni.showToast({
  5. title:'验证通过',
  6. mask:false,
  7. duration:1500
  8. })
  9. }

image.png

image.png

按钮的是否可以点击

刚开始不能点击按钮
image.png

  1. disabled:true

image.png

  1. <button class="user-set-btn"
  2. :class="['user-set-btn-disable':disabled]"
  3. @tap="submit" type="primary" :disabled="disabled">完成</button>

实时的监听3个值的输入
image.png

  1. watch:{
  2. oldpassword(val){
  3. },
  4. newpassword(val){
  5. },
  6. oldpassword(val){
  7. }
  8. },

image.png

  1. // 监听输入框
  2. change(){
  3. if(this.oldpassword && this.newpassword && this.renewpassword){
  4. this.disabled=false;
  5. }
  6. },

image.png

  1. watch:{
  2. oldpassword(val){
  3. this.change();
  4. },
  5. newpassword(val){
  6. this.change();
  7. },
  8. renewpassword(val){
  9. this.change();
  10. }
  11. },

image.png

  1. if (this.newpassword !== this.renewpassword) {
  2. uni.showToast({
  3. title: '确认密码和新密码不一致',
  4. icon: "none"
  5. });
  6. return false;
  7. }

image.png

  1. change(){
  2. if(this.oldpassword && this.newpassword && this.renewpassword){
  3. this.disabled=false;
  4. }
  5. this.disabled=true;
  6. },

image.png
这里要return 阻止掉, 不要再往下走了。
image.png

image.png
删掉任何一个 就无法点击
image.png

loading提交状态

image.png

  1. <button class="user-set-btn"
  2. :class="{'user-set-btn-disable':disabled}"
  3. :loading="loading"
  4. @tap="submit" type="primary" :disabled="disabled">完成</button>
  1. loading:false

image.png

image.png

为了显示loading的效果
image.png

image.png
loading后,还不能点击。
image.png

  1. this.loading=true;
  2. this.disabled=true;

image.png

  1. // 提交
  2. submit() {
  3. this.loading=true;
  4. this.disabled=true;
  5. if(!this.check()){
  6. this.loading=false;
  7. this.disabled=false
  8. console.log('审核没过,直接pass');
  9. return;
  10. }
  11. uni.showToast({
  12. title:'验证通过',
  13. mask:false,
  14. duration:1500
  15. });
  16. this.loading=false;
  17. this.disabled=false;
  18. }


本节代码

user-set-repassword.vue页面

  1. <template>
  2. <view class="body">
  3. <input type="text" v-model="oldpassword" class="uni-input common-input" placeholder="输入旧密码" />
  4. <input type="text" v-model="newpassword" class="uni-input common-input" placeholder="输入新密码" />
  5. <input type="text" v-model="renewpassword" class="uni-input common-input" placeholder="输入确认密码" />
  6. <button class="user-set-btn"
  7. :class="{'user-set-btn-disable':disabled}"
  8. :loading="loading"
  9. @tap="submit" type="primary" :disabled="disabled">完成</button>
  10. <!-- -->
  11. </view>
  12. </template>
  13. <script>
  14. export default {
  15. data() {
  16. return {
  17. oldpassword: '',
  18. newpassword: '',
  19. renewpassword: '',
  20. disabled:true,
  21. loading:false
  22. }
  23. },
  24. watch:{
  25. oldpassword(val){
  26. this.change();
  27. },
  28. newpassword(val){
  29. this.change();
  30. },
  31. renewpassword(val){
  32. this.change();
  33. }
  34. },
  35. methods: {
  36. // 监听输入框
  37. change(){
  38. console.log('change事件');
  39. if(this.oldpassword && this.newpassword && this.renewpassword){
  40. this.disabled=false;
  41. console.log('change事件,修改disable为false');
  42. return;
  43. }
  44. this.disabled=true;
  45. },
  46. // 验证层
  47. check() {
  48. if (!this.oldpassword || this.oldpassword == "") {
  49. uni.showToast({
  50. title: '旧密码不能为空',
  51. icon: "none"
  52. });
  53. return false;
  54. }
  55. if (!this.newpassword || this.newpassword == "") {
  56. uni.showToast({
  57. title: '新密码不能为空',
  58. icon: "none"
  59. });
  60. return false;
  61. }
  62. if (!this.renewpassword || this.renewpassword == "") {
  63. uni.showToast({
  64. title: '确认密码不能为空',
  65. icon: "none"
  66. });
  67. return false;
  68. }
  69. if (this.newpassword !== this.renewpassword) {
  70. uni.showToast({
  71. title: '确认密码和新密码不一致',
  72. icon: "none"
  73. });
  74. return false;
  75. }
  76. return true;
  77. },
  78. // 提交
  79. submit() {
  80. this.loading=true;
  81. this.disabled=true;
  82. if(!this.check()){
  83. this.loading=false;
  84. this.disabled=false
  85. console.log('审核没过,直接pass');
  86. return;
  87. }
  88. uni.showToast({
  89. title:'验证通过',
  90. mask:false,
  91. duration:1500
  92. });
  93. this.loading=false;
  94. this.disabled=false;
  95. }
  96. }
  97. }
  98. </script>
  99. <style>
  100. @import url('@/common/form.css');
  101. </style>

结束