Nuxt.js: Incorporate a way to include Vuex store plugins in Modules mode

Created on 31 Jan 2019  Â·  1Comment  Â·  Source: nuxt/nuxt.js

What problem does this feature solve?

Since the "Classic" store mode is being deprecated, I'm a little unclear as to the best way to integrate plugins that made expressly for the store.

My example is vuex-cache: https://github.com/superwf/vuex-cache

It uses a syntax that loads a plugin directly into the store instance like so:

import Vuex from 'vuex'
import vuexCache from 'vuex-cache'
const store = new Vuex.Store({
  state: {
    ...
  },

  plugins: [vuexCache],

  mutations: {
    ...
  },

  actions: {
    ...
  }
})

store.cache.dispatch('LIST')

Since we don't have a hook into Vuex.Store in Nuxt since it utilizes the directory hook, I'd like to see some way to connect a store plugin to Nuxt's instance of the store.

What does the proposed changes look like?

Perhaps a connection could be made in the index.js under the /store directory, or perhaps it's something that would have to be declared from within the nuxt.config?

This feature request is available on Nuxt community (#c8578)
feature-request

Most helpful comment

This feature already exists. Just export an array named plugins containing your vuex plugins that you want to apply to the current module.

So to apply a plugin to the vuex root module you would do the following:

store/index.js:

import myPlugin from „my-plugin“

export const plugins = [ myPlugin ]

// export const mutations = { ... }
// export const actions = { ... }

>All comments

This feature already exists. Just export an array named plugins containing your vuex plugins that you want to apply to the current module.

So to apply a plugin to the vuex root module you would do the following:

store/index.js:

import myPlugin from „my-plugin“

export const plugins = [ myPlugin ]

// export const mutations = { ... }
// export const actions = { ... }
Was this page helpful?
0 / 5 - 0 ratings

Related issues

nassimbenkirane picture nassimbenkirane  Â·  3Comments

surmon-china picture surmon-china  Â·  3Comments

o-alexandrov picture o-alexandrov  Â·  3Comments

shyamchandranmec picture shyamchandranmec  Â·  3Comments

vadimsg picture vadimsg  Â·  3Comments