I read a code, where it allows user to download attachment
<template #link="{ item, rowdata }">
<attachment-link
v-test-id="'attachment-link'"
:inventory-id="item"
:filename="rowdata['fileName']"
@download-attachment="downloadAttachment">
</attachment-link>
</template>
But in the downloadAttachment function, it returns undefined, why the emit still works?
@Emit('download')
private downloadAttachment(filename: string, attachmentId: string) {
return undefined;
}
The
return undefinedline is rather redundant because that's the default behavior in a function that has noreturnstatement.The return value of the
@Emit-decorated function does not cause anundefinedvalue to be emitted. When the function returns nothing (i.e.,undefined), the original event arguments from the caller are emitted, which enables event forwarding. On the other hand, when the function returns any non-undefinedvalue (evennull), only that value is emitted.So in your specific example, the
<attachment-link>'sdownload-attachmentevent is forwarded as thedownloadevent from the component. The emitted event data would still befilenameandattachmentId.