GithubHelp home page GithubHelp logo

Comments (3)

 avatar commented on May 30, 2024 3

Hey, I just fond the solution > I Post it here in case somebody is searching too.

I used the old version of the store, where you declare a "Vuex Instance" and export it.
The thing is that in Nuxt, the store is a function. And you need to export this function.

I mean, when you call your store outside of a .vue file, you need to call a function

So this is my strore :

/* eslint-disable camelcase */
import Vuex from 'vuex'

const createStore = () => {
  return new Vuex.Store({
    state: () => ({
      myValue: false,
    }),
    mutations: {
      myExampleMutation(state, myNewValue) {
        state.myValue = myNewValue
      }
    }
  })
}

export default createStore

Here is my router :

import Vue from 'vue'
import Router from 'vue-router'
import store from "@/store/index";

import Home from './pages/Home.vue'

Vue.use(Router)

const createRouterConst = new Router({
  mode: 'history',
  routes: [
    {
      path: '/',
      name: 'uselessRoute',
      component: Home
    }
  ]
})

  createRouterConst.beforeEach(async (to, from, next) => {
    try {
      console.log(store().myValue); // >>> It's how i call it
      next()
    } catch (error) {
      console.log(error)
    }
  })

export function createRouter() {
  return createRouterConst;
}

We can see that i called store().myValue in the createRouterConst.beforeEach() statement.
It's working for me.

from router-module.

 avatar commented on May 30, 2024

This issue as been imported as question since it does not respect router-module issue template. Only bug reports and feature requests stays open to reduce maintainers workload.
If your issue is not a question, please mention the repo admin or moderator to change its type and it will be re-opened automatically.
Your question is available at https://cmty.app/nuxt/router-module/issues/c38.

from router-module.

matamune94 avatar matamune94 commented on May 30, 2024

Have more idea for this, i mean a something better more.

from router-module.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.