Feature flags for Vue 3 and Nuxt — composables, directives, and safe rollouts
Sign up at flagbit.anethoth.com to get your SDK key. The free tier includes 1,000 evaluations/day.
npm install flagbit-vue
// composables/useFeatureFlag.js
import { ref, onMounted } from 'vue';
export function useFeatureFlag(flagKey, defaultValue = false) {
const enabled = ref(defaultValue);
const loading = ref(true);
onMounted(async () => {
try {
const res = await fetch(
'https://flagbit.anethoth.com/api/v1/evaluate', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-SDK-Key': import.meta.env.VITE_FLAGBIT_SDK_KEY
},
body: JSON.stringify({
flag_key: flagKey,
context: { user_id: getCurrentUserId() }
})
});
const data = await res.json();
enabled.value = data.value;
} catch {
enabled.value = defaultValue;
} finally {
loading.value = false;
}
});
return { enabled, loading };
}
// Component usage
<script setup>
import { useFeatureFlag } from '@/composables/useFeatureFlag';
const { enabled: showNewNav, loading } = useFeatureFlag('new-navigation');
</script>
<template>
<NewNavigation v-if="showNewNav" />
<LegacyNavigation v-else />
<!-- Or use v-show for instant switching -->
<PromoBanner v-show="showNewNav" />
</template>
// Vue directive for inline feature gating
// main.js
app.directive('feature', {
async mounted(el, binding) {
const res = await fetch('https://flagbit.anethoth.com/api/v1/evaluate', {
method: 'POST',
headers: { 'Content-Type': 'application/json', 'X-SDK-Key': SDK_KEY },
body: JSON.stringify({ flag_key: binding.value })
});
const { value } = await res.json();
if (!value) el.style.display = 'none';
}
});
// Usage: <div v-feature="'beta-section'">Beta content</div>
Show different component versions to different users — test new designs without risk.
Evaluate flags server-side in Nuxt's setup hook for flicker-free rendering.
Control which store actions are available based on feature flags.
Use Vue Router beforeEach to gate routes behind feature flags.
Define flags in your FlagBit dashboard with targeting rules and rollout percentages.
Call the evaluate endpoint from your Vue.js app with user context for targeted rollouts.
Enable, disable, or adjust rollouts in real-time. No redeployment needed.
Yes — use the composable in setup() or evaluate flags in server middleware for SSR.
Evaluate flags before mount or use Suspense to show a loading state while flags resolve.
Yes — call FlagBit from Pinia actions or getters. Cache results in the store.
Yes — provide a global $flag method via app.provide and inject it in any component.
Free tier includes 1 project, 10 flags, and 1,000 evaluations/day. No credit card required.
Get Your Free API Key