We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
@nutui/nutui
4.2.0
h5
无
`
const rules = { account: [ { required: true, message: '请输入账号'}, ], password: [ { required: true, message: '请输入密码'}, ] };
const submit = () => { // @ts-ignore formRef.value.validate().then(({ valid, errors }) => { if (valid) { console.log('success'); } else { console.log('error', errors); } }) }
</script>`
我在form表单上绑定了ref变量formRef,声明变量时,应该传入其泛型,以便调用其validate等方法时不会报错,我尝试从@nutui/nutui中寻找导出的form表单类型,但是并没有找到,此组件库是否不提供类型的导出
通过泛型处理form表单的类型,而不是使用 // @ts-ignore忽略typescript的报错
使用 // @ts-ignore忽略typescript的报错
No response
{ "name": "manager", "private": true, "version": "0.0.0", "type": "module", "scripts": { "dev": "vite", "build": "vue-tsc && vite build", "preview": "vite preview" }, "dependencies": { "@nutui/nutui": "^4.2.0", "amfe-flexible": "^2.2.1", "vue": "^3.3.4" }, "devDependencies": { "@types/node": "^20.8.9", "@types/postcss-pxtorem": "^6.0.2", "@vitejs/plugin-vue": "^4.2.3", "postcss": "^8.4.31", "postcss-pxtorem": "^6.0.0", "typescript": "^5.0.2", "unplugin-auto-import": "^0.16.7", "unplugin-vue-components": "^0.25.2", "vite": "^4.4.5", "vite-plugin-pages": "^0.31.0", "vite-plugin-vue-layouts": "^0.8.0", "vue-tsc": "^1.8.5" } }
The text was updated successfully, but these errors were encountered:
可以通过 InstanceType 获取组件类型,不过组件库提供导出更方便点。
InstanceType
<template> <nut-form ref="formRef"> <nut-button @click="handleSubmit">提交</nut-button> </nut-form> </template> <script lang="ts" setup> import { Form } from '@nutui/nutui-taro' type FormInstance = InstanceType<typeof Form> const formRef = ref<FormInstance>() const handleSubmit = async () => { try { await formRef.value?.validate() } catch (err) { console.log(err) } } </script>
Sorry, something went wrong.
在目前的组件库构建方式下,没有能力扩展出新的类型导出字段。 最近在测试对这部分逻辑的改造方案。
Successfully merging a pull request may close this issue.
NutUI 包名
@nutui/nutui
NutUI 版本号
4.2.0
平台
h5
重现链接
无
重现步骤
`
登录
登录const rules = {
account: [
{ required: true, message: '请输入账号'},
],
password: [
{ required: true, message: '请输入密码'},
]
};
const submit = () => {
// @ts-ignore
formRef.value.validate().then(({ valid, errors }) => {
if (valid) {
console.log('success');
} else {
console.log('error', errors);
}
})
}
</script>`
我在form表单上绑定了ref变量formRef,声明变量时,应该传入其泛型,以便调用其validate等方法时不会报错,我尝试从@nutui/nutui中寻找导出的form表单类型,但是并没有找到,此组件库是否不提供类型的导出
期望的结果是什么?
通过泛型处理form表单的类型,而不是使用 // @ts-ignore忽略typescript的报错
实际的结果是什么?
使用 // @ts-ignore忽略typescript的报错
环境信息
No response
其他补充信息
{
"name": "manager",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "vue-tsc && vite build",
"preview": "vite preview"
},
"dependencies": {
"@nutui/nutui": "^4.2.0",
"amfe-flexible": "^2.2.1",
"vue": "^3.3.4"
},
"devDependencies": {
"@types/node": "^20.8.9",
"@types/postcss-pxtorem": "^6.0.2",
"@vitejs/plugin-vue": "^4.2.3",
"postcss": "^8.4.31",
"postcss-pxtorem": "^6.0.0",
"typescript": "^5.0.2",
"unplugin-auto-import": "^0.16.7",
"unplugin-vue-components": "^0.25.2",
"vite": "^4.4.5",
"vite-plugin-pages": "^0.31.0",
"vite-plugin-vue-layouts": "^0.8.0",
"vue-tsc": "^1.8.5"
}
}
The text was updated successfully, but these errors were encountered: