News Articles vuex

When should I use store in React, Vue projects?

Currently, I am working on a Vue project and I met some problems. In the past, I used to save all the data in the store. Saving data in the store and use them when I need them, it helped me to write a clean, organized code. But now I’am faced with this situation. I […]

How to access Vuex store in Vue setup() method?

How do I access the Vuex store in Vue when using the setup() method? I don’t have access to the regular this.$store variable anymore. Source: JavaSript – Stack Overflow

how to use plugin’s globalProperties in a js file?

Using Vue 3. I have an auth plugin that sets a globalProperties.$auth: export default { install: function (app, options) { options.router.beforeEach((to, from, next) => { authDirects(to, next, options.store, options.config.loginRoute); }); app.config.globalProperties.$auth = authMethods(options.store, options.config) } } usage in components is fine but I’m moving to the vuex patterns, so I have these files: // store/modules/playlists.js […]

Can i create local vuex for one difficult component?

vue2 question I have many difficult components with same struct PersonCard components PersonForm components (many components) index.vue PersonImage components (many components) index.vue index.vue i want to create vuex instance for one this component, not global. at index.vue for PersonCard folder (root point of component) create vuex, and destroy if component destroy is it possible? Source: […]

Dexie not store data in production build, but all works normally in dev build

I wrote an app based on Vue v2 and Vuex that uses Dexie as data access layer to IndexedDB. Over Dexie, i put another layer that use Repository pattern to manage the creation and persistence of entity instances. All works fine while use dev-server of vue-cli. And also works fine when i build a dev […]

Nuxt: How to access store in rollbar.js WITHOUT using localStorage?

I am using Nuxt and Rollbar. I have a user id state in store. My question is, how can I set this user id as a custom payload in the transformer function in rollbar.js WITHOUT using localStorage? Here is my code: // plugins/rollbar.js const transformer = function(payload) { payload.user_id = user_id_from_store // how to get […]

Vuex: importing a single state from an object

I have a simple store: UsersStore.js state() { return { users: { name: ”, userHasPermissions: false, } } } I am trying to use mapState to have the state accessible in my component. When I import the entire User object of the store like below, it works: App.vue computed: { …mapState(‘users’, { myUser: ‘user’ } […]

How to handle Uncaught Error: [nuxt] store/index.js should export a method that returns a Vuex instance

I have setup a default store in Nuxt in store/index.js as the documentation recommends. When I try to render my app I’m getting the following error: Uncaught Error: [nuxt] store/index.js should export a method that returns a Vuex instance. My store/index.js file looks like this: import Vuex from ‘vuex’ import Vue from ‘vue’ import myModule […]

mapGetters[‘getters’] in variable (Decorator, ts, vue)

i want to find a solution to do that : @Component({ computed: { …mapGetters([‘getAllPosts’]) } }) export default class Dashboard extends Vue { allPosts = getAllPosts } i tried some things like : allPosts = this.$store.getter.getAllPosts but it is not work. Can you help me? Thanks Source: Vue – Stack Overflow

Access class method via Vue 3 + Vuex state + Typescript

Is it possible to access class methods via Vuex state? In the following situation, I want to call fullName() to display the user’s formatted name. TypeError: store.state.user.fullName is not a function Classes export class User { constructor( public id: string = ”, public first_name: string = ”, public last_name: string = ”, ) {} fullName […]

Init pinia state

We use pinia to manage app state. As it’s mentioned in title, I’m looking for NuxtServerInit hook analogue for pinia. A little context: User lands on First page of form; Form calls (f.e.) state.getCountries() to fetch the list of items for one of the select inputs; User selects a country and navigates to Second page, […]

IntersectionObserver triggers twice on Vuejs

I’m developing an app with VueJs. I need to create a price chart (candlestick chart, but it’s not important) out of my data array which has 40 chunks and each chunk has 1000 items. Since that is a lot of data, I’m trying to create a lazy loading. My plan is to merge the first […]

Products list is not mounting with loading component in Vuejs

I am using Vue-Router. So, before going to my root directory I am fetching some data from an API. Code is like this: async beforeRouteEnter(to, from, next) { let result = await axios.get(‘https://example.com’) next(vm => { vm.$store.commit(‘Products’, result.data.products); //storing them in Vuex Store window.localStorage.setItem(‘Products’, JSON.stringify(result.data.products)) }) Now, I want to load another Component. Like this: […]

Vite project. methods and computed in App.vue can’t see vuex store in build mode

When I use yarn dev it’s work fine! I can use this.Entity in methods and computed in App.vue. But yarn build/serve lost it. "this" just not included my storage when I trace it. This simple expl will work with yarn dev, but not with build->serve. <template> <button @click="toNextDay">End</button> </template> <script setup> import { computed } […]

methods and computed in App.vue can’t see vuex store in build mode. Vite project

When I use build then serve, "this" just not included my storage when I trace it. When I use yarn dev it’s work 100% fine, this.Entity give storage in methods and computed in App.vue. <template> <button @click="toNextDay">End</button> </template> <script setup> import { computed } from "vue"; import { useStore } from "vuex"; const store = […]

methods can’t see vuex store only whith build mode. Vite project

https://github.com/ShadowOfNaglfar/reproduce-error When I use build then serve, "this" just not included my storage when I trace it. But when I use yarn dev it’s work 100% fine. In this case this.Entity give storage in methods and computed in my App.vue. <template> <button @click="toNextDay">End</button> </template> <script setup> import { computed } from "vue"; import { useStore […]

methods can’t see vuex store whith build mode. Vite project

https://github.com/ShadowOfNaglfar/reproduce-error When I use build then serve, "this" just not included my storage when I trace it. But when I use yarn dev it’s work 100% fine. In this case this.Entity give storage in methods and computed in my App.vue. <template> <button @click="toNextDay">End</button> </template> <script setup> import { computed } from "vue"; import { useStore […]

when i refresh page session closed vue js firebase

I am trying to create a login system but when I enter the dashboard and then refresh the page, it closes the session and returns me to / Login This is my main.js: import { createApp } from ‘vue’ import App from ‘./App.vue’ import router from ‘./router’ import store from ‘./store’ import ‘./assets/bootstrap.js’ import firebase […]

Sitemap | Terms | Privacy | Cookies | Advertising

Senior Software Developer

Creator of @LzoMedia I am a backend software developer based in London who likes beautiful code and has an adherence to standards & love's open-source.