nuxt-community / nuxt-property-decorator

Property decorators for Nuxt (base on vue-property-decorator)
https://github.com/kaorun343/vue-property-decorator
MIT License
399 stars 34 forks source link

How to make visible the "nuxtServerInit" action for Nuxt.js action in the case with dynamic modules only? #95

Closed TokugawaTakeshi closed 2 years ago

TokugawaTakeshi commented 2 years ago

I am sorry for the question in issues. Before open this issue, I asked same question in StackOverflow and even did the contest. The only one answer does not contain the working solution.


According this answer on Stack overflow, below listing from the vuex-module-decorators official documentation

// @/store/index.ts
import Vuex from 'vuex'

const store = new Vuex.Store({
  /*
  Ideally if all your modules are dynamic
  then your store is registered initially
  as a completely empty object
  */
})

in the Nuxt case must be:

import Vue from "vue";
import Vuex, { Store } from "vuex";

Vue.use(Vuex);

export const store: Store<unknown> = new Vuex.Store<unknown>({});

But how to integrate the nuxtServerInit action is above methodology? In below listing of store/index.ts, the nuxtServerInit will not be called.

import Vue from "vue";
import Vuex, { Store } from "vuex";

Vue.use(Vuex);

export const store: Store<unknown> = new Vuex.Store<unknown>({
  actions: {
    nuxtServerInit(context: unknown): void {
      console.log("Called !");
      console.log(context);
    }
  }
});
DavidBernal commented 2 years ago

Hi @TokugawaTakeshi This is not related with this package but nuxt and vuex-module-decorators integration. Anyway I created this example repo that should be enough to solve your problems: link to repo

TokugawaTakeshi commented 2 years ago

@DavidBernal

It was the most polite issue rejection in the world. You made it work!

Now only removing of Classic mode for store/ is deprecated and will be removed in Nuxt 3. warning is not enough for 100% happiness. Because I know the cost of specialists' time, I feel uncomfortable to ask you to solve this for free. May I ask you to fix if for 50$? (Payment via PayPal).

TokugawaTakeshi commented 2 years ago

Updated the issue How to use with nuxtServerInit of vuex-module-decorators with my instance.

DavidBernal commented 2 years ago

Hi @TokugawaTakeshi
I would not worry about that warning. Also, I don't know how vuex will be on nuxt 3: nuxt/framework#571

TokugawaTakeshi commented 2 years ago

@DavidBernal Well, anyway, thank you for the solution!