vue.js - 是否可以在故事书装饰器中访问故事的数据?
问题描述
在 Vue.js 中,我有一系列自定义输入组件,它们具有v-model
. 在 Storybook 中,我想在decorator
我的故事中添加一个以显示我的自定义输入的当前值,如何在装饰器上访问组件的数据?
这是TextField.stories.js
故事:
import TextField from 'TextField';
import decorator from 'decorator';
export default {
title: 'Example/TextField',
component: TextField,
decorators: [decorator],
argTypes: {
update: { action: 'update' },
// value: { control: { type: 'text' } },
},
};
const Template = (args, { argTypes }) => ({
props: Object.keys(argTypes),
components: { TextField },
template: '<text-field v-model="value" @update="update" v-bind="$props" />',
data() {
return {
value: 'foo bar',
};
},
});
export const Simple = Template.bind({});
Simple.args = {
label: 'Simple Text Field',
};
这是decorator.js
,我想value
从这里的故事中访问:
export default () => ({
template: '<div class="m-5"><story /><pre class="bg-secondary mt-5 p-4">{{ value }}</pre></div>',
});
解决方案
您可以从全局装饰器访问单个故事的参数:
// preview.js:
export const decorators = [(storyFn, context) => {
const { label, ...otherArgs } = context.args;
// use in decorator output
}]
然后以 CSF 格式:
export const MyStory = ({ label, ...otherArgs }) => { ... }
MyStory.args = {
label: 'whatever',
// etc.
}
推荐阅读
- resharper - R# 参数提示,如何关闭它?
- node.js - npm start 命令给出 ELIFECYCLE 错误,errno 1
- django - Django外键字段过滤问题
- java - 未为加密/解密初始化密码
- matlab - 为什么我的第三个 MATLAB 函数在使用 ode45 时只输出零?
- shell - 来自不同数据文件的事件的直方图
- java - 如何解决不兼容类型错误?
- javascript - 用 JS 和时刻操作日期/时间
- excel - 在 Excel 中使用公式将小数点更改为逗号后保持自定义数字格式的文本
- tensorflow - tensorflow 估计器多次调用与亚当一起训练