dcits-ui
v0.1.28
Published
Downloads
12
Readme
Vue 3 + Typescript + Vite
- defineProps withDefaults
import { PropType, withDefaults, defineProps } from 'vue'
import type { ExtractPropTypes } from 'vue'
// 法一
type TestProps = {
name: string
age?: number
}
const props = withDefaults(defineProps<TestProps>(), {
name: '',
age: 18
})
// 法二
withDefaults(defineProps<{ name: string; age?: number }>(), {
name: 'hello vite',
age: 18
})
// 法三 类型反推
const treeProps = {
data: {
type: Array as PropType<string[]>,
default: () => []
}
}
type TreeProps = ExtractPropTypes<typeof treeProps>
- defineEmits
export const alertEmits = {
close: (evt: MouseEvent) => evt instanceof MouseEvent
}
export type AlertEmits = typeof alertEmits
const emit = defineEmits(alertEmits)
- defineExpose