|
76 | 76 | </view>
|
77 | 77 | <view class="u-config-item">
|
78 | 78 | <view class="u-item-title">错误提示方式</view>
|
79 |
| - <u-subsection vibrateShort :list="['文字', '下划线', '输入框', '下划线+文字']" @change="errorChange"></u-subsection> |
| 79 | + <u-subsection vibrateShort :list="['message', 'toast', '下划线', '输入框']" @change="errorChange"></u-subsection> |
80 | 80 | </view>
|
81 | 81 | </view>
|
82 | 82 | </view>
|
@@ -131,14 +131,32 @@ export default {
|
131 | 131 | trigger: ['change','blur'],
|
132 | 132 | },
|
133 | 133 | {
|
| 134 | + // 此为同步验证,可以直接返回true或者false,如果是异步验证,稍微不同,见下方说明 |
134 | 135 | validator: (rule, value, callback) => {
|
135 | 136 | // 调用uView自带的js验证规则,详见:https://www.uviewui.com/js/test.html
|
136 | 137 | return this.$u.test.chinese(value);
|
137 | 138 | },
|
138 | 139 | message: '姓名必须为中文',
|
139 | 140 | // 触发器可以同时用blur和change,二者之间用英文逗号隔开
|
140 | 141 | trigger: ['change','blur'],
|
141 |
| - } |
| 142 | + }, |
| 143 | + // 异步验证,用途:比如用户注册时输入完账号,后端检查账号是否已存在 |
| 144 | + // { |
| 145 | + // trigger: ['blur'], |
| 146 | + // // 异步验证需要通过调用callback(),并且在里面抛出new Error() |
| 147 | + // // 抛出的内容为需要提示的信息,和其他方式的message属性的提示一样 |
| 148 | + // asyncValidator: (rule, value, callback) => { |
| 149 | + // this.$u.post('/ebapi/public_api/index').then(res => { |
| 150 | + // // 如果验证出错,需要在callback()抛出new Error('错误提示信息') |
| 151 | + // if(res.error) { |
| 152 | + // callback(new Error('姓名重复')); |
| 153 | + // } else { |
| 154 | + // // 如果没有错误,也要执行callback()回调 |
| 155 | + // callback(); |
| 156 | + // } |
| 157 | + // }) |
| 158 | + // }, |
| 159 | + // } |
142 | 160 | ],
|
143 | 161 | sex: [
|
144 | 162 | {
|
@@ -410,12 +428,9 @@ export default {
|
410 | 428 | },
|
411 | 429 | errorChange(index) {
|
412 | 430 | if(index == 0) this.errorType = ['message'];
|
413 |
| - if(index == 1) this.errorType = ['border-bottom']; |
414 |
| - if(index == 2) { |
415 |
| - this.errorType = ['border']; |
416 |
| - this.border = true; |
417 |
| - } |
418 |
| - if(index == 3) this.errorType = ['message', 'border-bottom']; |
| 431 | + if(index == 1) this.errorType = ['toast']; |
| 432 | + if(index == 2) this.errorType = ['border-bottom']; |
| 433 | + if(index == 3) this.errorType = ['border']; |
419 | 434 | }
|
420 | 435 | }
|
421 | 436 | };
|
|
0 commit comments