(feat): Allow sharing of main app's context with toast app #290
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.
Description
When registering the plugin, it creates a new app instance wherein the toasts are created. That decouples your app's instance from the plugin's components and enables you to create instances in other contexts besides
app.use
.However, as a consequence of this independence, the contexts of Vue Toastification's app and the main app are not shared, so it is not possible to access things like the following from within custom toast components:
RouterLink
,NuxtLink
, etcThis PR creates an opt-in fix for that, through a new plugin option
shareAppContext
that overrides the default toast context with the main app's.More specifically, it overrides the following properties:
app._context.components
app._context.directives
app._context.mixins
app._context.provides
app.config.globalProperties
These should be enough for the majority of use cases. If it isn't, tweak it using the solution proposed in #162 (comment)
To enable the feature, do:
Related Issue
#162
Types of changes
Checklist: