[Vue Alert]: Render Error - "TypeError: Unable to retrieve the 'getters' property of an undefined object"

Here is the code snippet from my app.js file. Can someone please review it and confirm if I have defined the items correctly according to the Vuex documentation?

import store from "./store";
require('./bootstrap');
window.Vue = require('vue').default;
import vuetify from "./vuetify";
import router from "./router";
import AppComponent from "./components/AppComponent";
import Store from  "./store"
const app = new Vue({
  el: '#app',
  vuetify,
  router,
  Store,
  components:{
    "app-component":AppComponent,
  }
});

This section contains the content of my store.js file:

import Vue from 'vue'
import Vuex from  'vuex'
Vue.use(Vuex)

const departmentRoute= [
  { icon: 'mdi-account-badge-outline', text: 'مدیریت  مطالبات   ' ,link:'demands'},
  { icon: 'mdi-account-badge-outline', text: 'مدیریت  گزارشات   ' ,link:'reports'},
];
const SuperAdminRoute= [
  { icon: 'mdi-account-group-outline', text: '  مدیریت کاربران ' ,link:'users'},
  { icon: 'mdi-account-badge-outline', text: 'مدیریت  مطالبات   ' ,link:'demands'},
  { icon: 'mdi-account-badge-outline', text: 'مدیریت  گزارشات   ' ,link:'reports'},
  { icon: 'mdi-account-badge-outline', text: 'آمار و ارقام     ' ,link:'demands'},
];
const studentRoute= [
  { icon: 'mdi-account-group-outline', text: 'آخرین مطالبات به رای گذاشته شده' ,link:'selfDemand'},
  { icon: 'mdi-account-group-outline', text: 'مطالبات من  ' ,link:'selfDemand'},
  { icon: 'mdi-account-badge-outline', text: ' پیگیری مطالبه   ' ,link:'addReport'},
  { icon: 'mdi-checkbox-marked-circle-outline', text: 'تایید حساب کاربری' ,link:'verify'},
];
export default new Vuex.Store({
  state: {
    level: localStorage.getItem('role')
  },
  getters: {
    items: state => {
      switch (state.level) {
        case "super-admin":
          return SuperAdminRoute;
        case "department":
          return departmentRoute;
        default:
          return studentRoute;
      }
    }
  }
})

Lastly, this is an excerpt from my app component script:

<script>
import { mapGetters } from 'vuex'

export default {
  name: "MainDashboard",
  props: {
      source: String,
  },
  computed: {
    ...mapGetters(['items'])
  },
  data: () => ({
    drawer: null,
    title:'فاد | فارغ التحصیلی ناد',
  }),
  methods:{
    logout() {
      axios.post('/api/logout').then(res=>{
        localStorage.removeItem('token');
        localStorage.removeItem('role');
        this.$router.push('/login');
      }).catch(err=>{
      });
    }
  }
}
</script>

I am facing an issue where I can see my getters in the Vuex tab but not in the component's computed property. Any idea why this might be happening and how I can troubleshoot it? Could it be related to an incorrect import of Vuex?

Vuex Tab :

https://i.stack.imgur.com/q348b.png

Component :

https://i.stack.imgur.com/JW3jU.png

Answer №1

To correctly incorporate the store into your app, make sure to add it in either the app.js or main.js file as shown below:

import Vue from "vue";
import App from "./App.vue";
import store from "./store";

Vue.config.productionTip = false;

new Vue({
  render: (h) => h(App),
  store
}).$mount("#app");

If you try using

import {store} from "./store";
, it will result in an error.

Answer №2

i made a simple adjustment to this line

import Store from  "./store"

changed it to :

import store from  "./store"

resulting in the resolution of my issue!

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

Injecting dynamic variables into JSON objects using JavaScript

I am facing a challenge with populating values dynamically from an array of elements. Below is the primary array that I am working with. list = [{name: 'm1'}, {name: 'm2'},{name: 'm3'},{name: 'm4'},{name: 'm5&ap ...

The view named 'HelloWorld' could not be found within the servlet named 'dispatcherServlet'

I have recently started learning Spring Boot. My goal is to display an HTML page, but unfortunately I am facing some issues. When I change HelloWorld.html to HelloWorld.ftl, I am able to display the FTL page. However, the vue.js file is not being resolve ...

Adding HTML to a Vue instantsearch widget

I need assistance with converting a numerical value representing product ratings in a Vue instantsearch component into images of stars and half stars. Here is the code I have so far: <template> <ais-instant-search :search-client="searc ...

Utilizing numerous Nuxt vuetify textfield components as properties

Trying to create a dynamic form component that can utilize different v-models for requesting data. Component: <v-form> <v-container> <v-row> <v-col cols="12" md="4"> <v ...

Utilize data attributes in VueJS to dynamically style elements

Is there a way to utilize the data() values within the <style>..</style> section? I have experimented with different combinations (using/omitting this, with/without {{brackets}}, etc.) but haven't been successful. Interestingly, when I man ...

Mastering Array Dispatch in VueJS

I've encountered an issue while trying to send an array of data to the backend. I attempted to include [] in the dispatch variables and on the backend, but it only captures the last data sent to the backend. My objective is to associate each data with ...

The issue of passing a prop to a child component in Vue 3 has not been resolved as expected

Within my code, I have a simple file structured like this: <script setup> import { ref } from 'vue' import TheHeader from '@/components/_headerbar/TheHeader.vue' import TheSidebar from '@/components/_sidebar/TheSidebar.vue&ap ...

Tasks involving computed getters

Is it acceptable to assign properties in computed getters? props: invoice: type: Object computed: total: @invoice.subtotal = { some expression } I am considering this because the invoice object is shared among several other components, and ...

What seems to be the issue with the data initialization function not functioning properly within this Vue component?

In my Vue 3 component, the script code is as follows: <script> /* eslint-disable */ export default { name: "BarExample", data: dataInitialisation, methods: { updateChart, } }; function dataInitialisation() { return { c ...

Enhance your PrimeVue experience with the power of Tailwind CSS

After installing PrimeVue, I encountered an issue where the component style was not working, but Tailwind CSS was functioning correctly. It seems that when I install Tailwind first, it works fine until I add Primevue's button component, which then cau ...

How come the data from the Firebase real-time database is only displaying in the console and not on the page when using Vue.js?

I am encountering an issue while trying to display a value stored in my Firebase Realtime Database using the {{ exams.name }} syntax in Vue. Although I can see the value when I console.log it, it does not render on the page. However, when I attempted the s ...

The split function of a string displays an undefined result

My goal is to extract all characters that come after the equal sign within a URL: let url = this.$route.query.item console.log(typeof(url)) // outputs string let status = url => url.split('=')[1] When I run the code, it shows &apo ...

Issue with Laravel Composer: Failed to install, restoring original content in ./composer.json

I am fairly new to Laravel and I have been using Laravel 5.8 for my project development. Recently, I needed to access the file ExampleComponent.vue in the resources/js/components directory but it was not there. After referencing this link, I came to know ...

Can we import a CSS file selectively in Vue.js?

Can specific css-files be applied only when the current route has a "forAdmin" meta in my Vue.js project that includes both an admin-panel and client pages? ...

Bypassing redirection in Nuxt for seamless login experience

I've been exploring ways to implement authentication on my Nuxt app, but I'm struggling to find a tutorial that doesn't rely on redirecting to public or private paths. For example: if (user.isLoggedIn()) { redirect('/dashboard&apo ...

The preflight request for CORS failed the access control check due to not receiving an HTTP ok status

How can I resolve this issue? Backend: ASP .Net Web APP - API, IIS Frontend: Vue Error: https://i.stack.imgur.com/QG1Yw.png https://i.stack.imgur.com/3tKh7.png Fiddler: https://i.stack.imgur.com/diN08.jpg web.config: <httpProtocol> <cus ...

Is it possible to trigger the @click event in Vuejs when utilizing v-html to render HTML content?

Here is an interesting HTML scenario: errorText: '<a class="button" @click.prevent="enableExceedable(issue.mapping)">Enable exceedable limits</a>'; I am trying to insert this string into the following div: <div v-if="hasIssue != ...

Exploring Nuxt.js: A guide to server-side caching of axios calls for universal client access

I am currently working on a project using Vue and Nuxt.js. I am wondering if there is a way to cache an axios web service call for all clients. Specifically, I need to retrieve currency reference data and it seems inefficient for every client to make this ...

If I only use a data property for determining its existence, will a computed property still rely on it for its calculation?

Here is the Vue component in question: export default { data: function() { return { editor: new Editor({ //some options }), } }, computed: { doc(){ // <--------------------- pay ...

Problem with Vue app deployment in a subdirectory arises when the route changes from the specified publicPath

We are faced with a dilemma in our Vue application deployment to a subdirectory known as /deploypath/ Presently, our vue.config.js file looks like this: const { defineConfig } = require('@vue/cli-service') module.exports = defineConfig({ publi ...