Unable to access the 'mobile' property as it is not defined - Vue/Vuetify/Storybook

I am encountering an issue with the "canvas" screen on my storybook's Vue and Vuetify story. While other components are functioning correctly, this particular one is not working as expected. It appears that my story is unable to identify the 'mobile' property of Vuetify in this specific component. I have attempted to remove all SCSS related to mobile from the component, but without success.

The error displayed is:

TypeError: Cannot read property 'mobile' of undefined
    at VueComponent.isMobile (http://localhost:6006/vendors~main.68bb2399de94b0c69072.bundle.js:289475:23)
    at Watcher.get (http://localhost:6006/vendors~main.68bb2399de94b0c69072.bundle.js:243936:25)
    at Watcher.evaluate (http://localhost:6006/vendors~main.68bb2399de94b0c69072.bundle.js:244041:21)
    at VueComponent.computedGetter [as isMobile] (http://localhost:6006/vendors~main.68bb2399de94b0c69072.bundle.js:244291:17)
    at VueComponent.genHeaders (http://localhost:6006/vendors~main.68bb2399de94b0c69072.bundle.js:262289:24)
    at VueComponent.genDefaultScopedSlot (http://localhost:6006/vendors~main.68bb2399de94b0c69072.bundle.js:262621:178)
    at Object.normalized [as default] (http://localhost:6006/vendors~main.68bb2399de94b0c69072.bundle.js:242050:37)
    at Proxy.render (http://localhost:6006/vendors~main.68bb2399de94b0c69072.bundle.js:261032:66)
    at VueComponent.Vue._render (http://localhost:6006/vendors~main.68bb2399de94b0c69072.bundle.js:243005:22)
    at VueComponent.updateComponent (http://localhost:6006/vendors~main.68bb2399de94b0c69072.bundle.js:243523:21)

If I switch to the "docs" screen and reload the page, it renders properly.

Below are the Storybook configurations:

// main.js
const path = require('path');

module.exports = {
  "stories": [
    "../docs/**/*.stories.mdx",
    "../docs/**/*.stories.@(js|jsx|ts|tsx)"
  ],
  "addons": [
    "@storybook/addon-links",
    "@storybook/addon-essentials"
  ],
  webpackFinal: async (config, { configType }) => {
    config.resolve.alias = {
      ...config.resolve.alias,
      "~": path.resolve(__dirname, "../"),
      "@components": path.resolve(__dirname, "../src/components"),
    };
    config.module.rules.push({
      test: /\.scss$/,
      use: [
        'style-loader', 
        'css-loader',
        {
          loader: 'sass-loader',
          options: {
            additionalData: `
            @import "_variables";
            @import "_globals";
            @import "_main";
            `,
            sassOptions: {
              includePaths: ['src/assets/scss'],
            }
          },
        } 
      ],
      include: path.resolve(__dirname, '../'),
    });
    return config;
  }
}
// Preview.js

import { addDecorator } from '@storybook/vue';
import vuetify from './vuetify_storybook';     

export const parameters = {
  actions: { argTypesRegex: "^on[A-Z].*" },
}

addDecorator(() => ({
  vuetify,
  template: `
  <v-app style="height: 200px">
    <story/>
  </v-app>
  `
}))
// vuetify__storybook.js

import Vue from 'vue';
import Vuetify from 'vuetify';
import config from '../docs/plugins/vuetify.js';

Vue.use(Vuetify);

export default new Vuetify(config);
// vuetify.js (plugins/)

import Vue from 'vue';
import Vuetify from 'vuetify';
import 'vuetify/dist/vuetify.min.css';
import '@mdi/font/css/materialdesignicons.css';

Vue.use(Vuetify);

export default new Vuetify({
  theme: {
    themes: {
      light: {
        primary: '#5C068C',
        secondary: '#8345A5',
        accent: '#82B1FF',
        error: '#FF5252',
        info: '#2196F3',
        success: '#4CAF50',
        warning: '#FFC107'
      },
    },
  },
  icons: {
    iconfont: 'mdi',
  },
});

Answer №1

Finally found a successful solution after weeks of relentless experimentation:

To implement this workaround, simply insert the following line at the beginning of your .stories.js (or .ts) file:

import vuetify from '@/plugins/vuetify' // or wherever you initialized Vuetify

Then, when defining your storybook Template, make sure to include your vuetify object:

const Template = (args, { argTypes }) => ({
  props: Object.keys(argTypes),
  components: { YourComponent },
  vuetify, // <-- Crucial line
  template: `
  <v-app> <!-- ensure to wrap your component with v-app -->
    <YourComponent />
  </v-app>
  `
})

Once you run your story, everything should function as expected

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

Ways to combine two objects when a variable exists and is an object

Is there a way to merge two variables that are objects? I have experimented with the following code, and it seems to work: let data1 = { data1: "data1" } let data2 = { data2: "data2" } const items = { ...(data1 && typeof data1 === &apos ...

Is it possible to incorporate RequireJS in importing VueJS components?

I am currently working on a project that involves using both RequireJS and Vue components. One of my goals is to break down the Vue components into smaller pieces for better organization, and I want to be able to export these smaller components so they can ...

What is the process for transitioning data between SQL, PHP, and JavaScript seamlessly?

As a developer who frequently works on SQL/PHP applications, I often find myself constantly rewriting JavaScript code to accomplish the same tasks repeatedly. When dealing with simple APIs, it's not too difficult to create one-off AJAX methods to comm ...

What is the best way to save information from an ng-repeat loop into a variable before sending it to an API?

My goal is to store the selected value from ng-repeat in UI (user selection from dropdown) and assign it to a variable. function saveSelection() { console.log('inside function') var postToDatabase = []; vm.newApplicant.values ...

Use the map function to find the highest number within each array

function each(collection, func) { if (Array.isArray(collection)) { for (var i = 0; i < collection.length; i++) { func(collection[i], i); } } else { for (var key in collection) { func(collection[key], key); } } } functi ...

Easily modify and manage state on-the-fly using TextFields

Is the title conveying my intentions clearly? If not, please let me know. Essentially, I am looking to create a component that generates a form based on a JSON file. For example, if someone clicks on "light" in the navbar, I want the form to display fields ...

Tips for managing a date picker with JavaScript using the Selenium WebDriver

I have been attempting to scrape a travel website using Selenium Webdriver and Python. While I have successfully set the destination (destino) and place of origin (origem), I am encountering difficulties when trying to select a date. I understand that Ja ...

Show a nested array retrieved from JSON in a React component

I need assistance in displaying data from my JSON file, particularly an innested array using map(). The field I want to display as a list is analyzedInstructions, which looks like this: How to prep (from p How to prep /p) Steps: Remove the cauliflower&a ...

Tips for validating a react select dropdown list without relying on hooks

Is it possible to validate the selection made in a dropdown without using react-hook? I need to make sure that the selection is never empty or null when the user clicks on the submit button. handleChange = (option) => { this.setState({option: option.tar ...

Ensuring consistency of variables across multiple tabs using Vue.js

In my vuejs front-end, a menu is displayed only if the user is logged in. When I log out, the variable isLogged is updated to false, causing the menu to hide. If I have multiple tabs open with the frontend (all already logged in) and I logout from one tab ...

What is the best way to apply index-based filtering in Angular JS?

I am working on a tab system using ng-repeat to display tabs and content, but I'm facing some challenges in making it work seamlessly. Below are the tabs being generated: <ul class="job-title-list"> <li ng-repeat="tab in tabBlocks"> ...

What are the top recommendations for incorporating SVG inline within NuxtJS?

I have discovered a fantastic package that allows me to use SVG inline in NuxtJS and render it as HTML. The package I recommend is svg-inline-loader. This package enables the display of SVG as HTML, but it's important to note that all SVG elements mus ...

Learn the method of exhibiting array elements in a dropdown menu with React JS

I am struggling to display all 12 months in a dropdown using React JS. I have written the code below and used moment.js to fetch the months, which I can see in the console but they are not showing up in my dropdown menu. I tried to use .map() to display t ...

The specified container is not a valid DOM element

Recently, I decided to implement Redux into my React application. However, as I began setting everything up within my index.js file, I encountered an error message: https://i.sstatic.net/4kL2T.png. After some research, I learned that this error is related ...

Improving loading time for pages requiring jQuery to render

Currently, I am utilizing the Google PageSpeed service to enhance the loading time of my website. It is hosted on GAE/P, but that detail may not be crucial in this context. There are several resources my page relies on: Bootstrap (css and js) jQuery (js ...

The value of ng-repeat list in AngularJS does not update when its value is changed by an ajax call

I am completely perplexed. Why doesn't my ng-repeat update when there is an ajax call that changes its value? I have searched through many questions and answers here, but none of them address the issue with the ajax call. Here is the HTML: <div c ...

What are the steps to validate an Ajax form using Dojo JavaScript?

Currently, I am in the process of validating a form that has been written in Javascript/Dojo before sending it via Ajax. Here is the code snippet: <script src="http://ajax.googleapis.com/ajax/libs/dojo/1.6/dojo/dojo.xd.js" type="text/javascript" djConf ...

Guide to generating a PDF file and utilizing a Node.js program for the download process

Seeking assistance in creating a button using my Node.js application to generate a downloadable PDF file filled with information from a PostgreSQL database. Any help is greatly appreciated! ...

Tips for enhancing contrast in MUI dark theme modals

Currently, I am implementing MUI dark mode for my Next.js application. While the MUI modal functions perfectly in light mode, I am struggling with visibility issues when using it in dark mode. The contrast is not strong enough, making it difficult to disti ...

Is there a way to iterate through two arrays simultaneously in React components?

Recently delving into the world of React, I am utilizing json placeholder along with axios to fetch data. Within my state, I have organized two arrays: one for posts and another for images. state = { posts : [], images : [] ...