[Vuejs]-Can't read from Vuex store in Storybook

4👍

FYI, I was able to get this working by adding the following to preview.js:

import Vuex from 'vuex';
import Vue from 'vue'
import store from '../src/store/store'

Vue.use(Vuex);
Vue.prototype.$store = store;

2👍

EDIT: After browsing the Storybook docs, I see this:

You might be using global components or vue plugins such as vuex, in that case you’ll need to register them in this preview.js file

Their example code looks like this:

// Import Vue plugins
import Vuex from 'vuex';

// Install Vue plugins.
Vue.use(Vuex);

Have you done this in preview.js? (Keep in mind I’ve never looked at Storybook before, just browsing the docs.)


Original answer

The store has no default export, so that import syntax won’t work. You could grab the named export:

import { store } from './store'

Or you could change the store to use a default export:

export default new Vuex.Store({
  state: {
    count: 1
  },
})
👤Dan

Leave a comment