javascript - 如何映射枚举以选择 Storybook 中的下拉列表?
问题描述
我有一个像这样的简单 JS“枚举”
const MyEnum = {
Aaa: 1,
Bbb: 84,
};
我有一个简单的故事:
import MyEnum from 'models/my-enum';
import HotSpot from 'hot-spot/hot-spot.vue';
import hotSpotProp from './hot-spot.stories.defaults';
export default {
title: 'components/catalog/images/HotSpot',
args: {
hotspotProp: hotSpotProp,
currentWidth: 360,
selectedCallouts: [],
calloutMode: true,
originalWidth: 2100,
title: 'Example tooltip',
},
argTypes: {
oemId: {
options: Object.keys(MyEnum), // an array of serializable values
mapping: MyEnum, // maps serializable option values to complex arg values
control: {
type: 'select', // type 'select' is automatically inferred when 'options' is defined
// labels: MyEnum,
},
},
},
};
const Template = (args, { argTypes }) => ({
components: { HotSpot },
template: `<HotSpot v-bind="$props" />`,
props: Object.keys(argTypes),
});
export const Default = Template.bind({});
文档中的示例不起作用。
我有一个select
下拉菜单,但它返回 aString
而不是Number
来自映射。
我在控制台的故事书中收到错误:
[Vue warn]: Invalid prop: type check failed for prop "oemId". Expected Number with value NaN, got String with value "Aaa".
如何映射枚举以选择 Storybook 中的下拉列表?
解决方案
那个故事书文档的例子绝对是恐怖的。这是一个示例,它将立即向您展示该做什么。
myValueList: {
options: [0, 1, 2], // iterator
mapping: [12, 13, 14], // values
control: {
type: 'select',
labels: ['twelve', 'thirteen', 'fourteen'],
},
}
推荐阅读
- excel - 如何从主工作簿复制并将数据粘贴到多个工作簿上
- c++ - 如何使用 Mako SDK 检测 PDF 中的透明度?
- r - geom_polygon 颜色设置被忽略
- jfrog-cli - 如何设置 JFrog CLI 环境变量?
- javascript - 当我点击外部下拉菜单时关闭下拉菜单
- android - 将捆绑包中的多个 apk 合并为一个
- django - 数字海洋 Kubernetes + Django / PostgreSQL 在集群内出现数据库错误
- c# - 在 SQLite 中,TEXT 的最大容量是多少?
- mysql - 单个查询从多个表 Mysql 中计算数据
- c# - Python NET 调用 C# 方法并将 null 作为参数传递