-
Notifications
You must be signed in to change notification settings - Fork 546
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Global API updates: more details on mounting behavior + replacement for Vue.prototype #117
Conversation
|
||
// After | ||
const app = createApp() | ||
app.config.globalProperties.$http = () => {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how would we access this inside the setup
function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is essentially a legacy escape hatch and not for setup
function. You should just import things directly or use provide/inject
in setup functions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This won't work for legacy apps that use multiple instances and apply Vue.use
globally since you'd have to run app.use
in every one of them. If that's required only for legacy plugins shouldn't that be included only in the compatibility build with global registration on the prototype as usual? That way you won't have to rewrite that much and stay with global Vue.use
. Why would you need that hack for anything but legacy plugins? (Assuming that the new strategy for plugins is to utilize provide
\inject
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The "legacy" term I used was incorrect - it should be for "options/this-based usage". Even with setup
function this can still be used to expose globally available properties to templates.
With the global API change there is no once-for-all global configs anymore. 2.x multi-root-instance apps will have to be updated to configure each root instance individually. If all root instances share the same config, then it can be extracted into a shared function.
@@ -44,6 +46,8 @@ app.mixin(/* ... */) | |||
app.component(/* ... */) | |||
app.directive(/* ... */) | |||
|
|||
app.config.globalProperties.customProperty = () => {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there an interface that can be extended to type new properties?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd say just don't use this if using TS.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't this be better for people migrating TS projects using libraries that are not adapted yet (or that may never completely adapt) to the inject/provide?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no way to make this work in TS though. If users insist on using this with TS they'd have to shim the types themselves.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If users insist on using this with TS they'd have to shim the types themselves
Oh yeah, I just thinking of exposing an interface that can be extended by users to add their own typings
mode details on mounting behavior replacement for Vue.prototype vuejs/rfcs#117
Vue.prototype
in 2.xRendered