Is there a way to declare shared props and events between components in Vue 3? #7927
-
Hi! I need to declare same props and events for multiple sibling components, which are interchangeable. From this discussion I've learned that composables aren't ment to do it. Mixins are considered as a bad practice. But I cannot find a way to achieve declaring same interface (props + events) for multiple components. Is there any, or should I just copy-paste them between these components? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
up :) |
Beta Was this translation helpful? Give feedback.
-
When using the runtime versions of // config file
export const sharedProps = {
question: {
type: Object
},
}
export const sharedEmits = ['change:question'] <script setup>
import { sharedProps, sharedEmits } from '../path/to/config/file'
const props = defineProps({ ...sharedProps, customProp: { type: Object } })
const emits = defineEmits([ ...sharedEmits ])
</script> |
Beta Was this translation helpful? Give feedback.
-
const emit = defineEmits<{
['update:modelValue']: [wallets: Wallet[]]
}>()
@markglattback Any workaround for this use case? |
Beta Was this translation helpful? Give feedback.
When using the runtime versions of
defineProps
anddefineEmits
, you can just import from another file: