vue3 typescript 子控件props中type类型自定义

1.字符串数组

defineProps({
  acb: Array as () => string[]
})

2.简单对象

defineProps({
  company: Object as () => ({name: string, domain: string})
})

3.自定义类型

type Compay={ name:string,domain:string }
 
defineProps({ compmay: {
        type:Object as ()=> Compay
} })
 
-------------------------------------------------------------
interface Person {
  name:string
}
 
defineProps({
    person:{
      type:Object as ()=> Person
    }
})

4.函数

import { PropType } from 'vue'
 
type func=(args?: string[])=> string
 
defineProps({
     func:{
        type: Function as ()=> PropType<func>
     }
})
posted @ 2024-03-27 23:43  打个大大西瓜  阅读(76)  评论(0)    收藏  举报