mobx-vue provides Vue 2 bindings for MobX, a state management library that simplifies working with reactive data. It enables Vue components to automatically react to MobX-managed state changes, drawing inspiration from `mobx-react`. The current stable version, 2.2.0, ensures compatibility with a wide range of MobX versions (2 through 6) after a temporary breaking change in v2.1.0 that restricted support to MobX 6. The library's release cadence appears to be irregular, marked by significant version compatibility adjustments. A key differentiator is its unopinionated approach, allowing for a more framework-agnostic data layer, which can ease migration between different view libraries. It is explicitly designed for Vue 2 applications; for Vue 3 support, users should look to `mobx-vue-lite`. It supports both Vue's Options API and, with a strong recommendation, class-based components using `vue-class-component` and decorators.
npm install mobx-vueVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates creating a reactive MobX ViewModel using decorators and integrating it into a Vue 2 class component using the `@Observer` decorator from `mobx-vue`.
Upgrade your `mobx` package to version 6.x.x, or if you need compatibility with older MobX versions, ensure you are using `mobx-vue` v2.2.0 or earlier than v2.1.0.
Consult the MobX 6 migration guide if upgrading from older MobX versions to understand necessary `tsconfig.json` or `.babelrc` adjustments for decorators and Proxy support.
For Vue 3 projects, use `mobx-vue-lite`, which is the dedicated MobX binding library for Vue 3 based on the Composition API.
For TypeScript, ensure `tsconfig.json` includes `"experimentalDecorators": true`, `"emitDecoratorMetadata": true`, and `"useDefineForClassFields": true` under `compilerOptions`. For Babel, ensure `@babel/plugin-proposal-class-properties` is configured with `"loose": false` if using Babel < 7.13, or rely on `setPublicClassFields: false` assumption for Babel >= 7.13.
Wrap state modifications within MobX `@action` annotated methods or `action()` utility functions. For asynchronous operations, use `action.bound` or `flow`.
Ensure that properties decorated with `@observable` are initialized correctly within the class definition or constructor. If working with older MobX versions, use `extendObservable` for adding new observable properties to an already observable object. For MobX 6, verify decorator configuration.