Add the expose option and expose function #1251
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Vue 3.2 introduced
defineExpose, theexposeoption, and theexposefunction in thesetupcontext object. WhiledefineExposeis documented, the other two are not. This PR adds some documentation for those two forms ofexpose.RFC: https://github.com/vuejs/rfcs/blob/master/active-rfcs/0042-expose-api.md
While working on this I noticed that
mountreturns the internal instance, not the exposed instance. This made it trickier to create simple, complete examples. I'd have preferred the API example to useconst vm = Vue.createApp(...).mount(...)to grab the public instance, but that doesn't work. Instead I've used examples that show how to useexposebut without explicitly showing how to use the exposed properties. I've opened a PR to change this invue-next: vuejs/core#4606. If that gets merged we could revisit those examples to make them a little clearer.