Skip to content

Is there a way to declare shared props and events between components in Vue 3? #7927

Discussion options

You must be logged in to vote

When using the runtime versions of defineProps and defineEmits, you can just import from another file:

// 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>

Replies: 3 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by dlohvinov
Comment options

You must be logged in to vote
1 reply
@markglattback
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants