如何验证道具? (VUE3,Coption-API,打字稿)

发布于 2025-01-31 11:37:33 字数 394 浏览 0 评论 0原文

如何在打字条中使用验证器用于props值?

type Props = {
    name: string
    type?: string // how to use "validator" ?
    modelValue: any
}

const props = defineProps<Props>()

如何使其正如以下声明一样工作:

defineProps({
    type: {
        type: String,
        validator(value) {
            return ...
        }
    }
})

How to use validator for props value in typescript?

type Props = {
    name: string
    type?: string // how to use "validator" ?
    modelValue: any
}

const props = defineProps<Props>()

How to make it work as in the following declaration:

defineProps({
    type: {
        type: String,
        validator(value) {
            return ...
        }
    }
})

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

最近可好 2025-02-07 11:37:33

也许此堆栈溢出答案会帮助您:

但是通常,在这样的情况下,我只是去官方Vue Discord Server 从Vue Core团队那里获得最佳答案

maybe this stack overflow answer would help you:

but usually, in cases like this, I just go to the official Vue Discord server and ask my questions there to get the best answer from the Vue core team

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文