When incorporating pinia with Vue, encountering an error with the decorator that says "Error: Unable to access 'useCoreStore' before initialization" may happen

While implementing the vue-facing decorator in my current project, I encountered an issue with setting up pinia.

The structure of my component resembles the example provided here:

I have verified that decorators like @Setup are functioning correctly, indicating the correct setup of vue-facing-decorator.

This is how I am attempting to set up pinia:

export const useCoreStore = defineStore('core', {
  state: () => ({
    navCollapsed: false,
  }),
  getters: {},
  actions: {},
});

In the component:

import { useCoreStore } from '@/core';
import { mapActions } from "pinia";

@Component({
  setup() {
    const store = useCoreStore();
    debugger;
    return { useCoreStore: store };
  },
  methods: {
    ...mapActions(useCoreStore, [ "setNavCollapsed" ])
  }
})
class AppHeader extends Vue {

Upon running this code in the browser, I encounter an error and it fails to reach the debugger, showing:

Uncaught ReferenceError: Cannot access 'useCoreStore' before initialization

If I disable the mapActions section:

//...mapActions(useCoreStore, [ "setNavCollapsed" ])

I can see the debugger being triggered.

What would be the correct approach for utilizing pinia with the vue-facing-decorator package?

Answer №1

The problem at hand was related to importing.

Instead of directly accessing the store using @/core, I needed to access it as @/core/core.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

Using svg.js within a Vue component

I'm experiencing a major issue when trying to integrate the SVG.js library into my project. Even after adding it, I am still unable to draw anything on the page. Here are the relevant files in my project: -public/index.html <!DOCTYPE html> < ...

Encountering issues with binding collections using Vuefire and Firebase

Currently, I am developing a web application using VueFire along with Firebase as the backend. Within my Realtime Database, I have organized data into two collections: cities:{ 0: { name: Berlin, c ...

Tips for extracting a specific segment from a URL string

Take a look at the outcome of the console.log below: console.log('subscribe:', event.url); "https://hooks.stripe.com/adapter/ideal/redirect/complete/src_1E2lmZHazFCzVZTmhYOsoZbg/src_client_secret_EVnN8bitF0wDIe6XGcZTThYZ?success=true" I need to ...

Placing an image onto a THREE.js plane

Whenever I attempt to place a .png image on my plane, it simply vanishes. Could it be that THREE.js isn't compatible with Vue.js? Is there another 3D library that supports Vue.js? I'm also interested in adding an SVG, but I haven't quite f ...

Navigating through a React application with several workspaces - the ultimate guide

Currently, I am working on implementing a monorepo setup inspired by this reference: https://github.com/GeekyAnts/nativebase-templates/tree/master/solito-universal-app-template-nativebase-typescript In this repository, there are 4 distinct locations wher ...

What is the best way to implement the <b-pagination-nav> component in Bootstrap Vue?

I'm eager to begin using the featured in this guide. However, I'm struggling to figure out how to incorporate the tag into my website. The tutorial's instructions are unclear and as a newcomer, I'm finding it difficult to make it func ...

Encountering a Vue npm installation issue

When following a tutorial, version information can be crucial. [root@localhost my-project]# node -v v6.11.3 [root@localhost my-project]# npm -v 3.10.10 [root@localhost my-project]# vue --version 2.9.2 [root@localhost my-project]# cat /etc/redhat-releas ...

What is the best way to separate my Webpack/Vue code into a vendor.js file and exclude it from app.js?

My plan is to create two separate files, vendor.js and app.js, for my project. In this setup, vendor.js will contain the core code for Webpack and Vue.js, while app.js will solely focus on the Vue.js code specific to my application. To streamline this proc ...

What is the reasoning behind TypeScript allowing the reading of an undefined variable within a closure?

While exploring, I came across this detail that seems undocumented. Here's some legitimate TypeScript code that results in undefined being output: let x: number; const f= () => { const y= x; console.log(y); } f(); Playground Within the fu ...

Is there a way to use AJAX to @yield or @include one laravel blade template with another?

Can a blade view file be included in another blade view file using AJAX via @yield or @include? ...

React classes with external scripts

I'm currently working on embedding an external map service into my React application. The recommended way to integrate the API into a regular HTML web page is shown below: <script type="text/javascript" src="//map.search.ch/api/map.j ...

Why is the ionChange/ngModelChange function being triggered from an ion-checkbox even though I did not specifically call it?

I have an issue with my code involving the ion-datetime and ion-check-box. I want it so that when a date is selected, the checkbox should automatically be set to false. Similarly, if the checkbox is clicked, the ion-datetime value should be cleared. Link ...

Get the @types definition installed from a forked repository

Background Information I recently made a workaround for a single type definition in my fork of DefinitelyTyped. This fix is located on a specific branch within my fork. It's important to note that this fix is temporary and should not be merged back ...

What is the best way to choose an element within a component's template?

Is there a way to access an element that is defined in a component template? While Polymer has the $ and $$ to make this task simple, I am curious about how it can be done in Angular. Consider the example provided in the tutorial: import {Component} from ...

Obtain information from a CSV document within Highchart Angular

Is there a way to access and retrieve data from a CSV file stored in the assets folder of my local system? The CSV file contains 5 or 6 columns of information. Important: This is an Angular project, therefore jQuery is not available. ...

Creating, editing, and deleting data in Ng2 smart table is a seamless process that can greatly enhance

While working on my Angular 2 project, I utilized [ng2 smart table]. My goal was to send an API request using the http.post() method. However, upon clicking the button to confirm the data, I encountered the following error in the console: ERROR TypeErro ...

Integrating Multiple Select Boxes in VUEjs Templates

Struggling to build a rapport with Vue at work, I find myself facing an issue that I'm not sure how to resolve. Let me try to explain the problem to the best of my abilities with the limited Vue knowledge that I possess. Basically, I have a Vue compo ...

When importing another JavaScript file, the export default async function may not be fully executed

I am facing an issue while trying to define the axios baseURL by triggering an internal API call in http-common.js. When I import the module from http-common.js, it fails to obtain the axios object. Even after running the async function, it still doesn&apo ...

Utilizing Vuejs within Laravel's blade templates

Hey there, I'm looking to create a dormitory management system using Laravel and Vue.js. I need help figuring out how to display my data using a Vue component instead of the "welcome.blade.php" file in Laravel. I am utilizing API routes for this proje ...

Create vertical boundaries with the chartjs-plugin-annotation in conjunction with vue-chartjs

Trying to set 2 vertical lines as thresholds for a list of results from various tests. The issue arises when attempting to place the lines at values that do not exist within the result set, causing them to disappear. However, with the code below, the lines ...