Skip to content

wevu / index / defineProps

函数: defineProps()

调用签名

defineProps<PropNames>(props): { [K in string]: Readonly<{ [key in string]?: any }>[K] }

定义于: packages/wevu/src/macros.ts:53

defineProps 数组语法。

类型参数

PropNames

PropNames extends string = string

参数

props

PropNames[]

返回

{ [K in string]: Readonly<{ [key in string]?: any }>[K] }

示例

ts
const props = defineProps(['title', 'count'])
const { title } = defineProps(['title'])

调用签名

defineProps<PP>(props): { [K in string | number | symbol]: Readonly<ExtractPropTypes<PP>>[K] }

定义于: packages/wevu/src/macros.ts:74

defineProps 运行时 props 配置。

类型参数

PP

PP extends ComponentPropsOptions = ComponentPropsOptions

参数

props

PP

返回

{ [K in string | number | symbol]: Readonly<ExtractPropTypes<PP>>[K] }

示例

ts
const props = defineProps({
  title: String,
  count: Number,
  active: Boolean,
  color: {
    type: String,
    default: 'red',
  },
})

调用签名

defineProps<TypeProps>(): DefineProps<LooseRequired<TypeProps>, BooleanKey<TypeProps, keyof TypeProps>>

定义于: packages/wevu/src/macros.ts:93

defineProps 泛型类型声明。

类型参数

TypeProps

TypeProps

返回

DefineProps<LooseRequired<TypeProps>, BooleanKey<TypeProps, keyof TypeProps>>

示例

ts
const props = defineProps<{
  title?: string
  count: number
  active?: boolean
}>()

const props2 = defineProps<{
  size?: 'sm' | 'md' | 'lg'
}>()

Released under the MIT License.