- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个组件故事,需要由我的 Vuex 商店中的 ACTION 执行 API 调用。但是,Storybook 找不到该商店:Unhandled promise rejection TypeError: "this.$store is undefined"
.
我尝试通过 created
访问商店和 mounted
Vue 生命周期钩子(Hook),但每个都返回 undefined
.
我的 Vuex 商店在我的应用程序中正常工作。
我在故事书上奔跑 5.0.1
和 vuex 3.1.1
.
这是我的故事书config.js
:
// Taken from https://davidwalsh.name/storybook-nuxt & https://github.com/derekshull/nuxt-starter-kit-v2/blob/master/.storybook/config.js
import { addParameters, configure } from '@storybook/vue';
import { withOptions } from '@storybook/addon-options';
import { setConsoleOptions } from '@storybook/addon-console';
import { create } from '@storybook/theming';
import Vue from 'vue';
import VueI18n from 'vue-i18n';
// Vue plugins
Vue.use(VueI18n);
setConsoleOptions({
panelExclude: [],
});
// Option defaults:
addParameters({
options: {
/**
* show story component as full screen
* @type {Boolean}
*/
isFullScreen: false,
/**
* display panel that shows a list of stories
* @type {Boolean}
*/
showNav: true,
/**
* display panel that shows addon configurations
* @type {Boolean}
*/
showPanel: true,
/**
* where to show the addon panel
* @type {String}
*/
panelPosition: 'bottom',
/**
* sorts stories
* @type {Boolean}
*/
sortStoriesByKind: false,
/**
* regex for finding the hierarchy separator
* @example:
* null - turn off hierarchy
* /\// - split by `/`
* /\./ - split by `.`
* /\/|\./ - split by `/` or `.`
* @type {Regex}
*/
hierarchySeparator: /\/|\./,
/**
* regex for finding the hierarchy root separator
* @example:
* null - turn off multiple hierarchy roots
* /\|/ - split by `|`
* @type {Regex}
*/
hierarchyRootSeparator: /\|/,
/**
* sidebar tree animations
* @type {Boolean}
*/
sidebarAnimations: true,
/**
* enable/disable shortcuts
* @type {Boolean}
*/
enableShortcuts: true,
/**
* theme storybook, see link below
*/
theme: create({
base: 'light',
brandTitle: '',
brandUrl: '',
// To control appearance:
// brandImage: 'http://url.of/some.svg',
}),
},
});
const req = require.context('../src/components', true, /\.story\.js$/)
function loadStories() {
req.keys().forEach((filename) => req(filename))
}
configure(loadStories, module);
import { storiesOf } from '@storybook/vue';
import { withReadme } from 'storybook-readme';
import { withKnobs } from '@storybook/addon-knobs';
import HandoffMainView from './HandoffMainView.vue';
import readme from './README.md';
storiesOf('HandoffMainView', module)
.addDecorator(withReadme([readme]))
.addDecorator(withKnobs)
.add('Default', () => {
/* eslint-disable */
return {
components: { HandoffMainView },
data() {
return {
isLoading: true,
component: {
src: '',
data: [],
},
};
},
template: '<handoff-main-view :component="component" />',
};
});
<template>
<main class="o-handoff-main-view">
<div class="o-handoff-main-view__content">
<div
:class="[
'o-handoff-main-view__background',
background ? `o-handoff-main-view__background--${background}` : false
]"
>
<loader
v-if="isLoading"
:color='`black`'
class="o-handoff-main-view__loader"
/>
<div
v-else
class="o-handoff-main-view__ui-component"
:style="getUiComponentStyle"
>
<img
:src="uiComponent.src"
alt=""
>
<handoff-main-view-layer-list
:layers="uiComponent.data"
/>
</div>
</div>
</div>
<div class="o-handoff-main-view__controls">
<handoff-main-view-zoom-handler
:default-zoom-level="zoomLevel"
:on-change="updateZoomLevel"
/>
</div>
</main>
</template>
<script>
import { mapActions } from 'vuex';
import Loader from '../../01-atoms/Loader/Loader.vue';
import HandoffMainViewZoomHandler from '../HandoffMainViewZoomHandler/HandoffMainViewZoomHandler.vue';
import HandoffMainViewLayerList from '../HandoffMainViewLayerList/HandoffMainViewLayerList.vue';
export default {
components: {
Loader,
HandoffMainViewZoomHandler,
HandoffMainViewLayerList,
},
props: {
background: {
type: String,
default: 'damier',
},
component: {
type: Object,
required: true,
},
},
data() {
return {
isLoading: true,
zoomLevel: 1,
uiComponent: {
src: null,
}
};
},
mounted() {
this.setUiComponentImage();
},
methods: {
...mapActions('UiComponent', [
'ACTION_LOAD_SIGNED_URLS'
]),
async setUiComponentImage() {
const uiComponentImg = new Image();
const signedUrls = await this.ACTION_LOAD_SIGNED_URLS([this.component.id]);
uiComponentImg.onload = () => {
this.isLoading = false;
};
uiComponentImg.src = this.uiComponent.src;
},
},
};
</script>
最佳答案
我打赌在你的应用程序的某个地方,可能是 main.js
,你正在做类似的事情:
import Vuex from 'vuex';
Vue.use(Vuex);
const store = new Vuex.Store({
state,
mutations,
getters,
});
然后,在创建 Vue 应用程序时,您调用
new Vue({store, i18n...})
.
config.js
中使用“i18n”模块来锻造 Vue。 .您还需要在那里导入 Vuex 和商店。
关于vue.js - 如何让 Vuex 商店与 Storybook 一起使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56682493/
我对 React 真的很陌生,需要问。 我可以有一个 ReactJs Redux store在库中,然后在也有 Redux 商店的应用程序中使用该库? 他们俩都这样做: ..A
我有两个商店版本的 Magento 安装:商店 A 和商店 B。当您转到“mydomain.com”时,我收到以下错误消息: 'There was no Home CMS page configure
我有一个按钮,单击该按钮时,将使用提供的 url 创建一个 JSONstore。然后将商店加载到网格中。如果再次单击该按钮,它会再次添加所有信息(因此会列出两次)。我想要这样,当用户单击按钮时,它会清
已结束。 这个问题是 off-topic .它目前不接受答案。 想要改进这个问题? Update the question所以它是on-topic堆栈溢出。 关闭 9 年前。 Improve this
我在 main.js 中进行 session API 调用,并将响应中的值用作我的根存储的初始值。在 vuex 中,它是这样处理的, DataService.getSession() .then(
我正尝试在 Svelte 商店中维护实时股票报价,以便屏幕上的出价和要价实时更新。我不确定商店的结构如何来保持数据的 react 性和效率。数据来自 websocket,如下所示: {'symbol'
将 Magento 商店从企业版 1.10.1.1 降级到社区版 1.7.0.0 应遵循什么程序? 我做的步骤是: 备份 Magento EE 1.10.1.1 数据库 :) 将此数据库导入到一个名为
我试图在过去 2 天使用内部应用程序共享上传我的应用程序,但无论我做什么,我都无法让它工作。这就是我所做的: 在控制台中,我点击了应用 -> 发布 -> 内部应用共享 我上传了 apk 我将自己添加到
现在的情况: 我有一个实时系统并且运行良好。 我没有测试系统。 我们的实时系统是一个多商店,在一个网站上有多个商店 View 。 问题: 我需要再添加一个 storeview 并在该 livesyst
我正在建立一个拥有零售店和批发商商店的网站。每个产品中的产品都不同,因此不仅仅是针对用户类型调整定价的问题。我需要保护批发部分的密码,以便它只对登录用户可用。我正在使用一个模块来实现这一点,但它只适用
我在应用商店上有几个应用程序,我每天都会检查所有可用的国家/地区,看看是否有人对我的应用程序留下了评论以及它在付费评级最高的位置中处于什么位置。 花时间看 iTunes 变得非常无聊。但我得到的信息非
我正在从 appsettings.json 加载配置文件,其中保存了 api url。 我已经建立了带有效果的ngrx 7商店。我在 app.component.ts onInit 中调度 loadc
我正在尝试为 Angular ngrx 存储架构中的操作编写 reducer : 这是我的 reducer : export const registration = (state: any, {ty
我创建了一个 Windows 商店应用程序,并使用 Visual Studio IDE 将其与商店相关联。在 Visual Studio IDE 中有用于创建应用程序包和上传应用程序包的菜单选项。 我
我有这个代码可以过滤我的商店 onLicenseGridSelect: function(rowmodel, record, index, eOpts) { Ext.getStore('Lic
我已将应用程序发布到 Play 商店。问题是我的应用程序的标题是 XXX YYY,但是当我输入 XXX YYY 时,搜索列表/索引中没有应用程序,但是如果我输入 XXXYYY,我可以找到我的应用程序。
我需要将所有翻译从主存储导出到另一个。 最佳答案 导出数据库中core_translate 表的内容。您可以为此使用 phpmyadmin。 关于php - 如何将内联翻译导出到另一个 Magento
我正在尝试将某些组件 (USERS) 连接到我的商店。我将向您展示每个步骤。 首先我在 index.js 中创建我的商店: // composeWithDevTools helps to follow
我不久前问过这个问题,并大致了解了商店的用途以及为什么使用它的基本解释。 但是,我目前正在为我的公司开发一个网络应用程序,并且遇到了一些计算问题。 首先,我有大约 35 个数据变量。一次只使用其中的几
我是 ngrx 的新手,我只是想了解它,让它工作起来。 我已将 ngrx(8.3 版)添加到我的应用程序中。 我希望有一些东西处于根状态(如果可能的话),然后我的每个功能都有单独的状态。我从根状态开始
我是一名优秀的程序员,十分优秀!