- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 Vue 3 + Storybook。一切正常,除了当我单击“显示代码”时,它只显示所有内容而不仅仅是模板..我做错了什么?
这是我的故事:
import Button from './Button.vue';
export default {
title: 'Components/Button',
component: Button
};
const Template = (args) => ({
// Components used in your story `template` are defined in the `components` object
components: { Button },
// The story's `args` need to be mapped into the template through the `setup()` method
setup() {
return { args };
},
// And then the `args` are bound to your component with `v-bind="args"`
template: '<my-button v-bind="args" />',
});
export const Primary = Template.bind({});
Primary.args = {
primary: true,
label: 'Button',
};
export const Secondary = Template.bind({});
Secondary.args = {
label: 'Button',
};
export const Large = Template.bind({});
Large.args = {
size: 'large',
label: 'Button',
};
export const Small = Template.bind({});
Small.args = {
size: 'small',
label: 'Button',
};
最佳答案
正如您从下面的屏幕截图中看到的那样,它确实有效,正如您在 Vue 2 中所期望的那样。
但是,我在使用 Vue 3 时得到的结果与您相同。
简单的答案
它尚未在 Vue 3 中实现。
正如您在 source code 中看到的那样Storybook 的文档附加组件,
Vue 3 框架有一个单独的实现。然而,Vue 3 实现缺少源代码装饰器,它生成源代码的渲染版本。
修补程序
如果您不想等到 Storybook 团队发布更新,您可以使用以下代码根据您的参数生成您自己的文档。请记住,这并不涵盖所有用例。
const stringifyArguments = (key, value) => {
switch (typeof value) {
case 'string':
return `${key}="${value}"`;
case 'boolean':
return value ? key : '';
default:
return `:${key}="${value}"`;
}
};
const generateSource = (templateSource, args) => {
const stringifiedArguments = Object.keys(args)
.map((key) => stringifyArguments(key, args[key]))
.join(' ');
return templateSource.replace('v-bind="args"', stringifiedArguments);
};
const template = '<my-button v-bind="args" />';
const Template = (args) => ({
components: { MyButton },
setup() {
return { args };
},
template,
});
export const Primary = Template.bind({});
Primary.args = {
primary: true,
label: 'Button',
};
Primary.parameters = {
docs: {
source: { code: generateSource(template, Primary.args) },
},
};
另一个临时解决方案是手动编写源代码,而不是自动生成它。
Primary.parameters = {
docs: {
source: { code: '<my-button primary label="Button" />' },
},
};
关于vue.js - Storybook 在 Show Code 中显示所有内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66529241/
我想知道如何将外部 javascript 加载到故事书中的特定故事中。我现在能找到的唯一文档是如何在全局范围内做到这一点 https://storybook.js.org/docs/react/con
我的组件中有一个悬停样式: const style = css` color: blue; &:hover { color: red; } `; 您可以在 Storybook 中模
我正在使用Storybook Windows 7 上的版本 3.3.15 运行节点版本 6.3.1 和 npm 版本 3.10.6。 在运行故事书时,我在呈现操作面板的页面底部看到“没有可用的面板”消
我将 Storybook 与 React 项目一起使用,该项目也使用样式化组件。许多样式定义访问 :root 中 index.css 文件中定义的 CSS 变量值,该文件位于 src 目录的根目录。所
我正在使用明暗主题制作 PWA,我想创建我的 Storybook 明暗主题来反射(reflect)这些主题。 所以我创建了一个函数,如果我向它传递一个 Material UI 主题和一个基本名称,它将
我目前在正确加载模块方面遇到了 Storybook 的大问题。 我真的无法提供一个独立的例子,因为这些问题看起来如此不稳定且难以预测。 基本上故事书正在运行,它正在尝试导入文件,但是这一步出了点问题。
您可以使用 Storybook 将一个 .stories 文件导入到另一个 .stories 文件中吗? 例如我有 /component1/component1.tsx /component1/com
我在本地运行 Storybook 没有问题。我可以使用 npm runstorybook 命令启动它。但是,当我尝试在 Azure 应用服务中托管 Storybook 时,运行 npm run Sto
Storybook 非常适合展示和记录组件,但我也有一些实用函数和类,我想添加到 storybook 中,是否可以使用它的控件作为这些函数参数? 最佳答案 要为非 UI 元素编写文档,只需使用 MDX
嗨,有没有人在 NX 工作区中使用 Scss/Sass 在 Storybook 中使用 Angular9+? 有工作指南吗?它对我不起作用,所以我可能做错了什么。 (故事书和 NX 的新内容) 该应用
我已经试过了。 npx -p @storybook/cli sb init --type angular,在现有项目上,但失败了。 依赖关系看起来像: "dependencies": { "@
我正在尝试将项目的当前版本(基本上是 version 中的 package.json 字段)添加到故事书,以便故事书的消费者可以知道他们正在查看项目的哪个版本。但是,我发现这样做非常困难,我无法在配置
我想得到这个: 我的stories.tsx代码如下所示: export default { title: "Components/Switch", argTypes: { color:
我的React应用程序中有故事书,由于某种原因,当我运行yarn storybook时,它总是打开相同的故事(它会自动选择selectedKind和selectedStory)。如何手动选择默认故事?
当我编辑一个组件并发生热模块重新加载时,所有其他具有相同标题的故事都会消失。唯一仍然存在的是我刚刚编辑的组件的故事。 在 component1.stories.tsx 中: import * as R
您好,我是 React 的初学者,我正在试用 Storybook,当我尝试运行 Storybook 时出现以下错误。 **我尝试使用 npm update 进行更新,我认为与我的依赖项有冲突 ** E
我的 Storybook 不能很好地扩展大量组件,所以我希望我可以用 Storybook 异步注册故事 我喜欢使用的语法是这样的 const storyRoot = storiesOf(`${CORE
我正在尝试从旋钮迁移到控件,但遇到嵌套对象的问题。 举个例子,假设我有一个像这样的对象作为组件的 Prop ...... object : { properties: { color: 'bl
我是故事书的新手。当我浏览关于故事书的文档和视频时,我读到了旋钮插件。旋钮插件和控件看起来很相似。这两件事有什么区别? 最佳答案 Storybook 版本 6 引入了控件。它们取代了大多数用例的旋钮。
我注意到 Storybooks Options Docs 中的一个属性叫 selectedPanel我认为这将允许我预先选择一个插件面板。 我不清楚如何使用它。例子是: options: { sele
我是一名优秀的程序员,十分优秀!