Storybook encounters an undefined error with the Vuex store

Here is a snippet from my main.js file:

import './plugins';

import store from './store';

import FileUpload from './components/FileUpload';

export default {
    install(Vue) {
        Vue.component('file-upload', FileUpload);

        Vue.prototype.fileUploadStore = store;
    }
}

This is how my FileUpload component is structured:

<template>
    <div class="container">
        <form enctype="multipart/form-data">
            <h1>Upload files</h1>
            <div class="dropbox">
                <input type="file" name="file"/>
            </div>
        </form>
    </div>
</template>

<script>
    export default {
        name: 'file-upload',

        created() {
            this.newUploadRequest();
        },

        methods: {
            newUploadRequest() {
                return this.fileUploadStore.dispatch('fileupload/newUploadRequest');
            }
        }
    }
</script>

Additionally, here's an excerpt from my story file:

import FileUpload from '../resources/js/components/FileUpload';

export default {
  title: 'Components',
  component: FileUpload,
};

export const fileUpload = () => ({
  components: { FileUpload },
  template: '<file-upload/>'
});

But, I encountered the following error:

TypeError: Cannot read property 'dispatch' of undefined at VueComponent.newUploadRequest

I'm puzzled as to why my store object appears to be undefined. Any thoughts on this issue?

Answer №1

Vue.prototype.fileUploadStore = store;
was not executed because you forgot to run Vue.use(main.js module). To resolve this issue, you can use the following code:

Update Main.js

import Vue from 'vue'; // -----①
import './plugins';

import store from './store';

import FileUpload from './components/FileUpload';

Vue.component('file-upload', FileUpload); // -----②
Vue.prototype.fileUploadStore = store; // -----③

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Express receiving undefined data in Ajax POST request

I'm currently facing an issue with sending data to be parsed. The client-side script I have is as follows: function addURL(link) { console.log("Adding url..."); $.ajax({ type: "POST", url: location.protocol + "/ ...

The significance of the "$=" or "?=" symbols in lit-element illustrations

I'm struggling to comprehend the purpose of ?= or $= in these two instances: First Example: Lit-Element README <div id="box" class$="${this.uppercase ? 'uppercase' : ''}"> <slot>Hello World</slot> </div> ...

Can you please explain how to indicate a modification in a JSON object with Polymer, transferring information from Javascript, and subsequently displaying child elements?

Currently, I am creating a JSON file that contains a random assortment of X's and O's. My goal is to display these elements in a grid format using a custom Polymer element. Initially, everything works fine as I can see a new grid generated each t ...

The poster image functionality in videos is experiencing issues after updating to version 1.5.0 of the Azure Media Player

I've encountered a strange issue after updating my azure media player to version 1.5.0 - it's not displaying the poster image like it did in version 1.3.0. Below is the code I'm currently using: <div class="marginBlock" id="mediaPlayer" ...

One array comprises of all elements found in a separate array

After grappling with this problem for a while, I still haven't been able to find a solution. If I have 2 arrays structured like this: array1 = [ { name: 'John', age : 25}, { name: 'Jane', age : 58} ] array2 = [ { name: ...

Ways to resolve the issue "Module Not Found Error: Cannot locate module './src/bot/index'"

Whenever I run the command node src/index.js I encounter the following error message: Error: Cannot find module './src/bot/index' Require stack: C:\Users\MIMAR\Desktop\EJS\src\index.js What could be causing this er ...

405 error: NGINX blocking POST method in Django DRF Vue.js application

I have encountered a strange issue while building my ecommerce site. Everything seems to be working fine, except for the forms. When attempting to post content, I keep receiving a 405 method get not allowed error. It's confusing as I am trying to use ...

Obtain the identification number and full name from the typeahead feature

I am able to retrieve the name and ID, but I am only able to display the name. I have attempted using update and afterslected methods. Currently, I have this code which works well, however, it only fetches the name! $('input.typeahead').typea ...

Enforce the selective inclusion of specific classes in TailwindCSS cherry picking

Currently in my Vue project with TailwindCSS and Vite, I am trying to implement a dynamic width class based on the size of an array. const array = [1, 2, 3]; const width = computed(() => `w-1/${array.length}`); <div :class="width">Conte ...

When I remove a user as admin, I am unable to retrieve all users to update the data table

I am currently working on an Admin Dashboard that includes a section for users. This section features a simple table displaying all the users in the MongoDB database along with some information. Additionally, there are functionalities to add a new user and ...

Create a search feature based on names utilizing Node Express in conjunction with SQL database

After deciding to create an API with a search feature using SQL queries in node express, this is how I structured my code: app.get('/search/:query', (req, res) => { pool.getConnection((err, connection) => { if(err) throw err ...

Typescript error: Cannot access property "status" on type "never".ts(2339)

Currently, I have a method that utilizes nextjs/auth to sign in with credentials from a form. However, I am encountering a type checking error Object is possibly 'undefined'.ts(2532) const doStuff = async (values: any) => { const result: S ...

Importing Angular libraries with the * symbol

One of the key modules in my library is sha256. To import it, I had to use the following syntax: import sha256 from 'sha256'; However, while researching this issue, I came across a question on Stack Overflow titled: Errors when using MomentJS ...

Utilizing Vue.js Datepicker to Specify a Date Range for Birth Date and Death Date

My goal is to disable all dates after today in both fields. Additionally, if a date of death is selected first, I want to disable all dates after that in the date of birth field. Here is what I have done so far: <Datepicker :disabled-dates="disabled ...

Troubles with Installing CRA and NextJS via NPM (Issue: Failure to locate package "@babel/core" on npm registry)

Summary: Too Long; Didn't Read The commands below all fail with a similar error message... Couldn't find package "@babel/core" on the "npm" registry create-react-app test npm install --save next yarn add next Details of Running create-re ...

The PHP server is having trouble accepting a JavaScript object sent via AJAX

Hey there, I'm currently facing an issue with sending fields from a form saved in a JavaScript object to a PHP server. I have set up the AJAX communication, but when I try to access the object in PHP, I notice that the length is showing as 0 during de ...

What is the best way to retrieve a FireStore document ID from an object?

I'm in the process of trying to reference an auto-generated firestore document ID in order to create a subcollection within it. The issue I'm facing is that although I can locate the document ID, I'm struggling to save it to a variable in a ...

Tokenizing with jQuery UI

I have been following a tutorial that utilizes jQuery UI to generate Facebook tokens, as shown in this link: However, I am facing an issue where I need to pass two values through JSON: the ID and the NAME. The server-side script is structured as follows: ...

Guidelines on Sharing Redux Store with Client during Routing in Redux

I'm currently learning Next.js and facing an issue with maintaining the dispatched state on a newly built page after routing. Can anyone provide guidance on how to retain the state? Specifically, I have a sidebar where I want to preserve the state of ...

Issue with dynamic form JavaScript functionality after removing curly braces { } from a select tag in Rails

In my Rails form, there is a gender field defined as follows: <%= f.select :gender, ["Male","Female"],{class: "gender"} %> I also tried adding an onclick event like this: <%= f.select :gender, ["Male","Female"],{class: "gender"},onclick: "categ ...