Vue SDK
The Unleash Vue SDK lets you evaluate feature flags in Vue applications. It connects to Unleash or Unleash Edge to fetch evaluated flags for a given Unleash context.
You can use this SDK with Unleash Enterprise or Unleash Open Source.
For an overview of how Unleash SDKs work, including offline behavior, feature compatibility across SDKs, and default refresh and metrics intervals, refer to the SDK overview.
Installation
npm
yarn
Initialization
Using config
Or use the FlagProvider component like this in your entrypoint file (typically App.vue):
Initializing your own client
Or, using FlagProvider:
Deferring client start
By default, the Unleash client will start polling for toggles immediately when the FlagProvider component renders. You can delay the polling by:
- setting the
startClientprop tofalse - passing a client instance to the
FlagProvider
Deferring the client start gives you more fine-grained control over when to start fetching the feature toggle configuration. This could be handy in cases where you need to get some other context data from the server before fetching toggles, for instance.
To start the client, use the client’s start method. The below snippet of pseudocode will defer polling until the end of the asyncProcess function.
Check flags
To check if a feature is enabled:
Check variants
To check variants:
Defer rendering until flags fetched
useFlagsStatus retrieves the ready state and error events. Follow the following steps in order to delay rendering until the flags have been fetched.
Unleash context
Follow the following steps in order to update the unleash context:
Developer toolbar
The Developer Toolbar provides runtime flag overrides during development.
Refer to the complete Vue example on GitHub for a full implementation.