vuex-class offers a set of decorator-based binding helpers designed to integrate Vuex store interactions seamlessly within Vue components built with `vue-class-component`. It provides decorators such as `@State`, `@Getter`, `@Action`, and `@Mutation` that allow developers to map Vuex store properties directly to class properties, significantly reducing boilerplate. The current stable version is `0.3.2`, released in 2019, indicating a project in maintenance mode, primarily supporting Vue 2 and Vuex 3 ecosystems. Its release cadence has been infrequent since 2019, suggesting limited active development but continued stability for its target environment. A key differentiator is its highly declarative syntax for accessing Vuex, moving away from string-based `map` helpers or direct `this.$store` calls, making the component code cleaner and more readable for TypeScript users leveraging decorators. This approach provides strong typing and improved developer experience when combined with `vue-class-component`.
npm install vuex-classVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to use `vuex-class` decorators (`@State`, `@Getter`, `@Action`, `@Mutation`) and the `namespace` helper to bind Vuex store properties to a class-style Vue component, showcasing both explicit and inferred property name mapping for a full interaction example.
Ensure your project's `package.json` specifies peer dependencies within the compatible ranges: `vue: "^2.5.0"`, `vuex: "^3.0.0"`, and `vue-class-component: "^6.0.0 || ^7.0.0"`. Update your `npm` or `yarn` lock files.
Update `tsconfig.json` to include `"allowSyntheticDefaultImports": true`. Also, ensure `"experimentalDecorators": true` and `"emitDecoratorMetadata": true` are enabled for decorator support. Verify Vue and vue-class-component versions meet the minimum requirements.
Always be mindful of property names when omitting arguments. For clarity and to avoid potential mismatches, it is often safer to explicitly provide the Vuex type string as an argument, e.g., `@State('myActualState') myStateProperty`.Ensure `tsconfig.json` has `"experimentalDecorators": true` and `"emitDecoratorMetadata": true` under `compilerOptions`.
Double-check the exact string passed to the decorator (`@Action('myActionName')`) against your Vuex store definition. If using namespaced modules, ensure the `namespace` helper and its path are correct, e.g., `someModule.Action('myAction')`.Run `npm install vuex-class` or `yarn add vuex-class`. Verify that `node_modules` is accessible and your `tsconfig.json` is correctly configured to include `typeRoots` if you have custom type declaration paths.
Ensure your Vuex store is created and passed to the root Vue instance: `new Vue({ store, ... }).$mount('#app')`. If using sub-components, confirm they inherit the store correctly.