Quickstart by stack
Vue Quickstart
Install the Vue SDK, add the plugin to your app, and read flags with useFlag, useVariant, and FlagGate, in Vue 3, Vite SSR, and Nuxt.
Prerequisites
- Vue 3.4 or newer and @zenmanage/sdk 3.5.1 or newer.
- A client key (prefixed cli_) stored in build-time configuration for the browser. Server rendering needs a server key (prefixed srv_) from a server-only environment variable. Mobile keys are not valid for this package.
- A flag key you can test in a non-production environment.
npm install @zenmanage/vue @zenmanage/sdk vue
import { createApp } from 'vue';
import { createZenmanagePlugin } from '@zenmanage/vue';
import App from './App.vue';
const app = createApp(App);
app.use(createZenmanagePlugin({ environmentToken: import.meta.env.VITE_ZENMANAGE_CLIENT_KEY }));
app.mount('#app');
<script setup lang="ts">
import { useFlag } from '@zenmanage/vue';
const { value: enabled, isLoading } = useFlag('new-checkout-button', false);
</script>
<template>
<button v-if="isLoading" disabled>Loading...</button>
<button v-else>{{ enabled ? 'Checkout (New)' : 'Checkout' }}</button>
</template>
Safe defaults, explicit loading
Every composable takes a default and returns it until the flag resolves, and again if evaluation fails. isLoading and error are explicit refs, so you decide what the UI does in each state. The type of the default decides how the flag is read: boolean, string, number, or JSON. If the API is unreachable, you get your defaults and no error.
Built on the JavaScript SDK
The package is a thin wrapper around @zenmanage/sdk, so caching, context handling, and defaults behave the same way they do in the JavaScript quickstart. Pass your own client to the plugin if you already have one.
import { computed, ref } from 'vue';
import { Attribute, Context } from '@zenmanage/sdk';
import { createZenmanagePlugin, useFlag } from '@zenmanage/vue';
// Pass a ref or getter and every flag re-evaluates when the user changes.
const context = computed(
() => new Context('user', user.value.name, user.value.id, [new Attribute('plan', [user.value.plan])])
);
app.use(createZenmanagePlugin({ environmentToken: import.meta.env.VITE_ZENMANAGE_CLIENT_KEY, context }));
// Inside a component, the key can change too.
const section = ref('billing');
const { value: limit } = useFlag(() => `${section.value}-limit`, 100);
<script setup lang="ts">
import { useVariant } from '@zenmanage/vue';
const { variant, isLoading } = useVariant('checkout-flow', 'control');
</script>
<template>
<p v-if="isLoading">Loading checkout...</p>
<OnePageCheckout v-else-if="variant === 'one-page'" />
<MultiPageCheckout v-else />
</template>
<FlagGate flag-key="beta-chat">
<BetaChat />
<template #disabled><LegacyChat /></template>
<template #loading><ChatSkeleton /></template>
</FlagGate>
const timeout = useConfig('api-timeout-ms', 5000);
const copy = useConfig('hero-copy', 'Welcome');
const { value: ui } = useFlag('ui-config', { theme: 'light', pageSize: 20 });
const { value: steps } = useFlag<string[]>('onboarding-steps', []);
Client keys only in the browser
Use a cli_ key in the browser. A srv_ key throws there, and a cli_ key throws in Node.js. Never ship a server key to the browser — read it from a server-only environment variable.
Server-side rendering
On the server, composables load their flags while Vue renders, so the HTML carries the real values. The server hands the flags the page read to the browser, which starts from the same values, so hydration doesn't mismatch or flash the default. The server shares one client between requests and caches rules for 60 seconds unless you set cacheTtl.
import { createSSRApp } from 'vue';
import { renderToString } from 'vue/server-renderer';
import { buildBootstrapScript, createZenmanagePlugin } from '@zenmanage/vue';
// Once per request, with a server key from a server-only environment variable
const plugin = createZenmanagePlugin({
environmentToken: process.env.ZENMANAGE_SERVER_KEY!,
context, // the current user
});
const app = createSSRApp(App);
app.use(plugin);
const html = await renderToString(app);
const bootstrap = buildBootstrapScript(await plugin.runtime.getBootstrapPayload());
// Load the client entry after the bootstrap script so the browser can hydrate.
return `<body><div id="app">${html}</div>${bootstrap}<script type="module" src="/src/entry-client.ts"></script></body>`;
import { createSSRApp } from 'vue';
import { createZenmanagePlugin } from '@zenmanage/vue';
const app = createSSRApp(App);
// With no bootstrap option, the plugin reads the server's <script> tag from the page.
app.use(createZenmanagePlugin({ environmentToken: import.meta.env.VITE_ZENMANAGE_CLIENT_KEY }));
app.mount('#app');
import { createZenmanagePlugin, type BootstrapPayload } from '@zenmanage/vue';
export default defineNuxtPlugin(async (nuxtApp) => {
const config = useRuntimeConfig();
if (import.meta.server) {
const plugin = createZenmanagePlugin({ environmentToken: config.zenmanageServerKey });
nuxtApp.vueApp.use(plugin);
// Once the page has rendered, hand the flags it read to the browser through the Nuxt payload.
nuxtApp.hook('app:rendered', async () => {
nuxtApp.payload.zenmanage = await plugin.runtime.getBootstrapPayload();
});
return;
}
nuxtApp.vueApp.use(
createZenmanagePlugin({
environmentToken: config.public.zenmanageClientKey,
bootstrap: (nuxtApp.payload.zenmanage as BootstrapPayload | undefined) ?? null,
})
);
});
export default defineNuxtConfig({
runtimeConfig: {
// NUXT_ZENMANAGE_SERVER_KEY: a server key (srv_...). It never reaches the browser.
zenmanageServerKey: '',
public: {
// NUXT_PUBLIC_ZENMANAGE_CLIENT_KEY: a client key (cli_...).
zenmanageClientKey: '',
},
},
});
Next step
Take the next integration step in your own stack.
Start with the quickstart that matches your runtime, then return to the reference pages when you need exact request and payload details.
Language and framework names and logos shown above are trademarks or registered trademarks of their respective owners. Their use here is for identification purposes only and does not imply endorsement of, or affiliation with, Zenmanage.