chore: demo ts (#8160)

* chore: demo ts

* chore: fix
This commit is contained in:
neverland
2021-02-14 19:50:45 +08:00
committed by GitHub
parent 8cbf153073
commit a8060bb599
20 changed files with 96 additions and 79 deletions

View File

@@ -38,9 +38,10 @@
</demo-block>
</template>
<script>
<script lang="ts">
import { reactive, toRefs } from 'vue';
import { useTranslate } from '@demo/use-translate';
import { FieldValidateError } from '../../field/types';
import Toast from '../../toast';
const i18n = {
@@ -49,7 +50,7 @@ const i18n = {
title: '校验规则',
submit: '提交',
message: '请输入正确内容',
invalid: (val) => `${val} 不合法,请重新输入`,
invalid: (val: string) => `${val} 不合法,请重新输入`,
pattern: '正则校验',
validator: '函数校验',
validating: '验证中...',
@@ -61,7 +62,7 @@ const i18n = {
title: 'Validate Rules',
submit: 'Submit',
message: 'Error message',
invalid: (val) => `${val} is invalid`,
invalid: (val: string) => `${val} is invalid`,
pattern: 'Use pattern',
validator: 'Use validator',
validating: 'Validating...',
@@ -80,11 +81,11 @@ export default {
value4: '',
});
const validator = (val) => /1\d{10}/.test(val);
const validator = (val: string) => /1\d{10}/.test(val);
const validatorMessage = (val) => t('invalid', val);
const validatorMessage = (val: string) => t('invalid', val);
const asyncValidator = (val) =>
const asyncValidator = (val: string) =>
new Promise((resolve) => {
Toast.loading(t('validating'));
@@ -94,11 +95,14 @@ export default {
}, 1000);
});
const onSubmit = (values) => {
const onSubmit = (values: Record<string, string>) => {
console.log('submit', values);
};
const onFailed = (errorInfo) => {
const onFailed = (errorInfo: {
values: Record<string, string>;
errors: FieldValidateError[];
}) => {
console.log('failed', errorInfo);
};