Skip to content

computed property does not read store in Nuxt #1

@simongcc

Description

@simongcc

Hello! I have implemented similar solutions and applied the following to store/index.js
Just share here in case anyone needed

Because by the time if loading the computed property by Nuxt, it is not yet mounted, so any after-mount property for non-ssr environment such as `this.$store.state.route.path is not yet available.

// store/index.js
// tested on nuxt@1.4.0
import { sync } from 'vuex-router-sync'

export default {
  actions: {
    async nuxtServerInit ({ dispatch }, { app }) {
      console.log('nuxtServerInit in index');
      sync(app.store, app.router); // for life cycle such as computed value which is before mounted
    }
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions