Closed grahamsutton closed 5 years ago
You can manage the parent state by simply assigning normal JavaScript variables outside the root-<div>
. You can then also see and interact with the state on the <Anonymous>
-parent-component within the VueJS-dev-tools.
In your case, the following should work:
<docs>
\```jsx
let show = false
<div>
<modal :show="show">
<span slot="header">Modal Title</span>
</modal>
<button @click="show = true" class="button button-primary">Launch Modal</button>
</div>
\```
</docs>
As far as I know, the code preview comes from Vue-Styleguidist and its functionality is documented here.
Thanks for the reply. I just tried this out and it works. My apologies, I am not very familiar with Vue-Styleguidist and their docs. I will have to look into it more.
Perhaps maybe we can update the documentation to include an brief example of controlling parent state, or at least include a link to it in context within the docs?
You can also define it as a Vue component inside the docs tags, with methods, data and anything else you can normally define, like so:
```vue
<template>
<modal :show="show">
<span slot="header">Modal Title</span>
</modal>
<button @click="show = true" class="button button-primary">Launch Modal</button>
</template>
<script>
export default {
data() {
return {
show: false
}
},
}
</script>
\```
Thanks @lukenofurther, that worked for me. I'll go ahead and close the issue.
Hi there.
Currently, I am trying to create a demo for my
<modal>
component, however, I only really demonstrate how it works unless I use it in conjunction with another element like a<button>
to launch the modal. Unfortunately, I don't believe VDS supports the ability to manage a "parent" state in the<docs>
tags of a component. Without this behavior, my demo looks empty and there is essentially nothing to interact with to demonstrate how the modal works.For example, here is what I wish I could do, but cannot (I put a
\
because of the GitHub markdown, but it's not in my actual code):however, this always ends up with this error:
Reasons I think this should be supported:
Also, if this ability is supported, I don't believe there is sufficient documentation on it or it is difficult to find.
Thank you for taking the time to review this issue.