storybookjs/storybook

Using args/controls to change vue's local state

Open

#12,073 opened on 2020年8月17日

GitHub で見る
 (23 comments) (4 reactions) (0 assignees)TypeScript (89,909 stars) (10,058 forks)batch import
argsfeature requesthas workaroundhelp wantedtriage:reviewedvue

説明

I was under the impression that with storybook 6 I can change values in vue's data() property without my component using props. I Use TS and have declared two data properties: userMenuOpen and text. The code below reflects what i want to do. If it's not possible like with 5 I misunderstood.

Vue, typescript, storybook 6

Component:

export default class TopNavBar extends Vue {
  userMenuOpen: boolean = false;
  text: string = 'hello';
}

Story:

export default {
  title: 'nav/TopNavBar',
  excludeStories: /.*Data$/,
  decorators: [StoryRouter()],
  component: TopNavBar,
  argTypes: {
    userMenuOpen: { control: 'boolean' },
    text: { control: 'text' },
  },
};

const Template = (args: any, { argTypes }: any) => ({
  components: { TopNavBar },
  data() {
    return {
      userMenuOpen: args.userMenuOpen,
      text: args.text,
    };
  },
  template: '<top-nav-bar  />',
});

export const Rounded = Template.bind({});
Rounded.args = {
  userMenuOpen: true,
  text: 'A different text',
};

コントリビューターガイド