Flagmint Vue.js SDK
A lightweight and powerful feature flag SDK for Vue 2 and Vue 3 applications with real-time updates via WebSocket.Features
Vue 2 & 3 Support
Works seamlessly with both Vue 2 and Vue 3
Real-time Updates
WebSocket and HTTP long-polling support
Segment Targeting
Advanced targeting rules and rollout strategies
Offline Ready
Built-in caching and preview mode
Installation
TypeScript support is built-in with full type declarations included.
Quick Start
Vue 3 Setup
Vue 2 Setup
Configuration Options
ThecreateFlagmintPlugin accepts a FlagClientOptions object:
| Option | Type | Default | Description |
|---|---|---|---|
apiKey | string | required | Your Flagmint API key |
context | Record<string, any> | {} | User attributes for targeting (e.g., user_id, email, country) |
autoRefresh | boolean | true | Automatically refresh flags when context changes |
refreshIntervalMs | number | 30000 | Polling interval for HTTP mode (milliseconds) |
persistContext | boolean | false | Store context in localStorage |
enableOfflineCache | boolean | true | Enable offline flag caching |
cacheTTL | number | 3600000 | Cache time-to-live (1 hour default) |
transportMode | 'auto' | 'websocket' | 'long-polling' | 'auto' | Connection mode (auto tries WebSocket first) |
previewMode | boolean | false | Local-only mode (no network calls) |
onError | (err: Error) => void | undefined | Error callback handler |
Using Flags
Vue 3 - Composition API (Recommended)
Vue 3 - Options API
Vue 2 - Using Mixin
Vue 2 - Options API
Feature Component
Use the built-in<Feature> component for declarative flag checking:
Reactive Flags
Get all flags as a reactive object that automatically updates:Updating Context
Update user context dynamically (triggers flag re-evaluation):Preview Mode (Local Testing)
Enable preview mode for local development without API calls:Targeting Rules & Rollouts
Flags support sophisticated targeting with rules and segments:Supported Operators
| Operator | Description |
|---|---|
eq | Equal to |
neq | Not equal to |
in | In array |
nin | Not in array |
gt | Greater than |
lt | Less than |
exists | Attribute exists |
not_exists | Attribute doesn’t exist |
Rollout Strategies
Percentage RolloutReal-time Updates
With WebSocket transport, flags update automatically when changed in Flagmint:Transport Modes:
auto- Tries WebSocket, falls back to long-pollingwebsocket- WebSocket only (fails if unavailable)long-polling- HTTP polling only
Testing Your Integration
Use the Flagmint SDK Tester to verify your implementation:- ✅ Both WebSocket and REST transport testing
- ✅ Visual context builder
- ✅ Protocol event logging
- ✅ Flag evaluation verification
- ✅ Network debugging
SDK Testing Tool
Test your Vue.js integration with our interactive testing tool
Advanced Usage
Manually Control Initialization
Error Handling
Inject Pattern (Vue 3)
API Reference
Plugin Methods
getFlag(key: string, defaultValue?: any): any
Get a flag value (non-reactive).
getReactiveFlags(): Record<string, any>
Get all flags as a reactive object.
updateContext(context: Record<string, any>): void
Update user context and re-evaluate flags.
setFlags(flags: Flag[], segmentsById: Record<string, Segment>): void
Manually set flags (useful in preview mode).
$flagmintReady: Promise<void>
Promise that resolves when flags are initialized.
Best Practices
Use Reactive Flags
Use Reactive Flags
For better performance and automatic updates, use
getReactiveFlags() instead of getFlag() in templates.Await Initialization
Await Initialization
Always wait for
$flagmintReady or useFlagmintReady() before accessing flags to avoid race conditions.Provide Default Values
Provide Default Values
Always provide sensible defaults when calling
getFlag() to handle loading states gracefully.Use Auto Transport
Use Auto Transport
Set
transportMode: 'auto' to get WebSocket with automatic fallback to long-polling if WebSocket fails.Example: Feature Toggle
Example: A/B Testing
Roadmap
- Segment evaluation
- Rollout strategies (percentage & variant)
- Preview/local-only mode
- Composables and mixins
- WebSocket + long-polling fallback
- Feature component
- SSR / Nuxt support
- Variant analytics
- Remote override via devtools
Troubleshooting
Flags not loading
Flags not loading
Symptoms: Flags return default valuesSolutions:
- Verify your API key is correct
- Check that you’re awaiting
$flagmintReadyoruseFlagmintReady() - Ensure your network allows WebSocket connections to api.flagmint.com
- Check browser console for errors
Flags not updating in real-time
Flags not updating in real-time
Symptoms: Changes in Flagmint dashboard don’t reflect in appSolutions:
- Confirm
transportModeis set to'auto'or'websocket' - Check WebSocket connection in browser DevTools (Network tab)
- Verify
autoRefresh: trueis set - Ensure you’re using
getReactiveFlags()not cachedgetFlag()calls
TypeScript errors
TypeScript errors
Symptoms: Type errors with flag methodsSolutions:
- Ensure you’re using TypeScript 4.5+
- Import types explicitly if needed:
Support
npm Package
View on npm registry
SDK Tester
Test your integration
API Reference
Full API documentation
Contact Support
Get help from our team