Error "[vuex] unknown action type:" in Nuxt, however I did all exactly according "Accessing modules with NuxtJS" documentation
See original GitHub issueLet me repeat: I did all according Accessing modules with NuxtJS explanations.
Store Module:
import { Action, Mutation, VuexModule, Module } from 'vuex-module-decorators';
@Module({
stateFactory: true,
name: "AUTHENTICATION__STORE_MODULE"
})
export default class AuthenticationStoreModule extends VuexModule {
private _token: string | null = null;
@Action
public async signIn(formData: { userId: string, password: string }): Promise<void> {
console.log("Called!");
const token: string = await new Promise(
(resolve: (token: string)=> void): void => {
setTimeout(() => { resolve('mock-token'); }, 2000);
});
console.log(token);
}
// ...
}
TypeScript types validation is all right. However, await authenticationStoreModule.signIn(formData)
does not work.
Component:
import { Vue, Component, Prop } from 'vue-property-decorator';
import VueReferencesInspector from '~/utils/VueReferencesInspector';
import { authenticationStoreModule } from "~/store/";
interface IElementUiForm extends Vue {
validate: (validationResult: (valid: boolean)=> void)=> void;
}
@Component
export default class extends Vue {
// ...
private onSubmit(): void {
// ...
try {
console.log('~~~');
console.log(authenticationStoreModule);
console.log(authenticationStoreModule.signIn(formData));
await authenticationStoreModule.signIn(formData);
this.$router.push('/admin');
} catch (error) {
this.dataIsBeingSubmittedNow = false;
}
});
}
}
console.log
s are;
As you see authenticationStoreModule
and authenticationStoreModule.signIn
are not undefined. However, console.log("Called!");
did not output, so action signIn
has not been called.
Once npm install
done,
- Execute
npm run dev
- go to page
http://localhost:3000/admin/login
- Try to login
You will see same console errors as in image.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:4
- Comments:27 (9 by maintainers)
Top Results From Across the Web
Vuex, Nuxt: Unknown action type - Stack Overflow
When commiting/dispatching I constantly get error "unknown action/mutation type: name". Also my mutations and actions don't display in vue ...
Read more >Vuex Unknown Action Type - ADocLib
[vuex] unknown action type: in Nuxt however I did all exactly according gives error: unknown mutation type: login I'm trying to split up...
Read more >Creating Server-side Rendered Vue.js Apps Using Nuxt.js
In this article, Toptal Freelance Front-end Engineer Ben Jones introduces us to Nuxt.js, a server-side rendering library for Vue.js, inspired by the popular ......
Read more >Unknown action type - nuxt - Vue Forum
I am trying to output a store action from my NUXT project, here is my action: export const actions = { async fetchTodos({...
Read more >Store - Nuxt TypeScript
There are a number of different options for writing and accessing the store in a Nuxt project using TypeScript. Class-based. vuex-module-decorators.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
It took me some trial and error, and the documentation & examples don’t mention this at all, but it seems that you have to
export default
your module classes. See my minimal example that seems to work correctly.Try:
For Nuxt usage you should match the filename and namespace of your module, so this module should be in
~/store/auth.ts
.