This repository has been archived by the owner on Feb 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 380
InjectReactive Default doesnt work. #238
Labels
Comments
AliLozano
added a commit
to AliLozano/vue-property-decorator
that referenced
this issue
Aug 9, 2019
Any update on this? |
Using @AliLozano 's commit, if you don't want to wait for a merge you can just create your own decorator:
|
The solution provided by @Conaire doesn't work, at least not for me. export function InjectReactive(options?: InjectOptions | InjectKey) {
return createDecorator((componentOptions, key) => {
if (typeof componentOptions.inject === 'undefined') {
componentOptions.inject = {};
}
if (!Array.isArray(componentOptions.inject)) {
const fromKey = options ? (options as any).from || options : key;
const defaultVal =
(Boolean(options) && (options as any).default) || undefined;
if (!componentOptions.computed) componentOptions.computed = {};
componentOptions.computed![key] = function () {
const obj = (this as any)[reactiveInjectKey];
// return obj ? obj[fromKey] : defaultVal
// >>> This is where to set the default value
return typeof obj[fromKey] === 'undefined' ? defaultVal : obj[fromKey];
};
componentOptions.inject[reactiveInjectKey] = reactiveInjectKey;
}
});
} |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Code
Behavior expected:
Results:
The text was updated successfully, but these errors were encountered: