refactor: 统一调整 defineEmits 写法

This commit is contained in:
Hooray Hu 2023-05-23 23:15:12 +08:00
parent dc625c3c26
commit 6632ffbc65
5 changed files with 47 additions and 16 deletions

View File

@ -24,7 +24,13 @@ const props = withDefaults(
},
)
const emit = defineEmits(['onSuccess'])
const emits = defineEmits<{
'onSuccess': [
res: any,
file: UploadUserFile,
fileList: UploadUserFile[],
]
}>()
defineOptions({
name: 'FileUpload',
@ -49,7 +55,7 @@ const onExceed: UploadProps['onExceed'] = () => {
}
const onSuccess: UploadProps['onSuccess'] = (res, file, fileList) => {
emit('onSuccess', res, file, fileList)
emits('onSuccess', res, file, fileList)
}
</script>

View File

@ -28,7 +28,14 @@ const props = withDefaults(
},
)
const emit = defineEmits(['update:url', 'onSuccess'])
const emits = defineEmits<{
'update:url': [
url: string,
]
'onSuccess': [
res: any,
]
}>()
defineOptions({
name: 'ImageUpload',
@ -52,7 +59,7 @@ function previewClose() {
}
//
function remove() {
emit('update:url', '')
emits('update:url', '')
}
const beforeUpload: UploadProps['beforeUpload'] = (file) => {
const fileName = file.name.split('.')
@ -76,7 +83,7 @@ const onProgress: UploadProps['onProgress'] = (file) => {
const onSuccess: UploadProps['onSuccess'] = (res) => {
uploadData.value.progress.preview = ''
uploadData.value.progress.percent = 0
emit('onSuccess', res)
emits('onSuccess', res)
}
</script>

View File

@ -30,7 +30,14 @@ const props = withDefaults(
},
)
const emit = defineEmits(['update:url', 'onSuccess'])
const emits = defineEmits<{
'update:url': [
value: string[],
]
'onSuccess': [
res: any,
]
}>()
defineOptions({
name: 'ImagesUpload',
@ -58,7 +65,7 @@ function previewClose() {
function remove(index: number) {
const url = props.url
url.splice(index, 1)
emit('update:url', url)
emits('update:url', url)
}
//
function move(index: number, type: 'left' | 'right') {
@ -69,7 +76,7 @@ function move(index: number, type: 'left' | 'right') {
if (type === 'right' && index !== url.length - 1) {
url[index] = url.splice(index + 1, 1, url[index])[0]
}
emit('update:url', url)
emits('update:url', url)
}
const beforeUpload: UploadProps['beforeUpload'] = (file) => {
@ -94,7 +101,7 @@ const onProgress: UploadProps['onProgress'] = (file) => {
const onSuccess: UploadProps['onSuccess'] = (res) => {
uploadData.value.progress.preview = ''
uploadData.value.progress.percent = 0
emit('onSuccess', res)
emits('onSuccess', res)
}
</script>

View File

@ -19,7 +19,14 @@ const props = withDefaults(
},
)
const emit = defineEmits(['update:modelValue'])
const emits = defineEmits<{
'update:modelValue': [
value: string[] | {
code: string
name: string
}[],
]
}>()
defineOptions({
name: 'PcasCascader',
@ -85,7 +92,7 @@ const myValue = computed({
},
// code
set: (value) => {
emit('update:modelValue', value ? codeToAny(value) : [])
emits('update:modelValue', value ? codeToAny(value) : [])
},
})

View File

@ -12,9 +12,13 @@ const props = withDefaults(
},
)
const emit = defineEmits<{
(event: 'update:fold', value: boolean): void
(event: 'toggle', value: boolean): void
const emits = defineEmits<{
'update:fold': [
value: boolean,
]
'toggle': [
value: boolean,
]
}>()
defineOptions({
@ -25,12 +29,12 @@ const isFold = ref(props.fold)
watch(() => props.fold, (value) => {
isFold.value = value
emit('update:fold', value)
emits('update:fold', value)
})
function toggle() {
isFold.value = !isFold.value
emit('toggle', isFold.value)
emits('toggle', isFold.value)
}
</script>