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
Vue $root component data access or setup #6548
Comments
Hi everyone! Seems like there hasn't been much going on in this issue lately. If there are still questions, comments, or bugs, please feel free to continue the discussion. Unfortunately, we don't have time to get to every issue. We are always open to contributions so please send us a pull request if you would like to help. Inactive issues will be closed after 30 days. Thanks! |
Hey there, it's me again! I am going close this issue to help our maintainers focus on the current development roadmap instead. If the issue mentioned is still a concern, please open a new ticket and mention this old one. Cheers and thanks for using Storybook! |
@shilman can we reopen this? I have the same question. |
Here's a sort of ugly workaround for this. Just add a decorator that wraps every story and manually assign $root in there. Something along the lines of this: addDecorator({
i18n,
beforeCreate: function() {
this.$root._i18n = this.$i18n;
},
template: '<div><slot /></div>',
}) |
using |
@backbone87 any ideas on how you use provide in a decorator? Thanks |
Sorry @graup , missed your comment back in June. Still an issue? |
Hi everyone! Seems like there hasn't been much going on in this issue lately. If there are still questions, comments, or bugs, please feel free to continue the discussion. Unfortunately, we don't have time to get to every issue. We are always open to contributions so please send us a pull request if you would like to help. Inactive issues will be closed after 30 days. Thanks! |
@shilman yes, I believe this is still an issue, albeit a low priority one since there are possible (hacky) workarounds. Looks like nobody has a need for this strong enough to whip up a PR. |
I have the same issue and when I use this.$root.isMobile in my components for my app and inject those components in storybook which is in another context it doesn't work. @Stale I actually have a need for that :) |
@graup I tried your workaround by doesn't work for me. Could you please give me info on that with some more code examples ? :) I would appreciate it. |
@naimlatifi5 I only tested it with vue-i18n, but I don't have any complete example right now. If you could post a link to a test repo, I can try to take a look there. |
Hi @graup, |
@naimlatifi5
|
Hi everyone! Seems like there hasn't been much going on in this issue lately. If there are still questions, comments, or bugs, please feel free to continue the discussion. Unfortunately, we don't have time to get to every issue. We are always open to contributions so please send us a pull request if you would like to help. Inactive issues will be closed after 30 days. Thanks! |
Hey there, it's me again! I am going close this issue to help our maintainers focus on the current development roadmap instead. If the issue mentioned is still a concern, please open a new ticket and mention this old one. Cheers and thanks for using Storybook! |
@gilesbutler I was able to create a global decorator to add support for inject/provide using a decorator In your preview.js add the following: export const decorators = [
(story, { args, parameters }) => {
const valueMap = new Map();
const newArgs = { ...args };
parameters.inject?.forEach((attribute) => {
valueMap.set(attribute, args[attribute]);
delete newArgs[attribute];
});
const WrapperComponent = defineComponent({
setup() {
valueMap.forEach((value, key) => {
provide(key, value);
});
},
template: "<slot />",
});
story({ args: newArgs });
return {
components: { story, WrapperComponent },
template: "<WrapperComponent><story /></WrapperComponent>",
};
},
]; Then in your story add what you'd like to inject with the 'inject' parameter: export default {
title: "MyComponent",
component: MyComponent,
parameters: {
inject: ["isPlaying"],
},
}; And add the value you'd like to pass in, in the stories args: export const Default = Template.bind({});
Default.args = {
isPlaying: false,
} |
Nice one, thanks @Juice10 |
If Vue project's $root component has a reactive variable (in data or computed) f.e.
isMobile
, so it can be used in app's components as$root.isMobile
, then there is no way to define it inconfig.js
or anywhere globally for storybook usage.It would be nice to have some option to define $root component's data, computed and methods.
Alternative solution that I use now, but it has annoying performance and usability cases:
Add variable as
Vue.prototype.isMobile
Does anyone have alternative solutions? or perhaps there is a way to add data or computed to root component in storybook?
The text was updated successfully, but these errors were encountered: