storybook Support multiple types for Vue

pgx2nnw8  于 3个月前  发布在  其他
关注(0)|答案(1)|浏览(28)

描述bug

我的一些组件可以接受不同类型的props,例如String或Number,但是当涉及到Storybook时,它将输入渲染为对象。我不确定这是否是一个bug,或者它应该表现得像那样,但如果有可能选择props中指定的类型之一并为此类型渲染输入字段,那就太好了。

重现

  • component.vue*
<template>
  <element :height=""height" :width="width" />
</template>

<script lang="ts">
import Vue from "vue";

export default Vue.extend( {
  name: 'component',
  props: {
    'width':{
      type: [String, Number],
      default: undefined,
    },
    'height':{
      type: [String, Number],
      default: undefined
    },
  },

) 
</script>
  • component.stories.js*
import component from "../components/component.vue";

export default {
  title: "Component",
  component: component,
};

export const Component = (args, { argTypes }) => ({
  components: {
    component,
  },
  props: Object.keys(argTypes),
  template: '<component v-bind="$props" />',
});
nmpmafwu

nmpmafwu1#

嘿,@vitalii-bulyzhyn,我不确定这是否是vue-docgen-api(从参数中推断类型的底层机制)的错误,但你可以手动指定参数的类型,可能解决你的问题:
https://storybook.js.org/docs/vue/api/argtypes#manual-specification

相关问题