Remove Modules
Before enabling Bridge’s Composition API, remove these packages:- Remove
@vue/composition-apifrom your dependencies - Remove
@nuxtjs/composition-apifrom your dependencies (and from your modules innuxt.config)
package.json
Using @vue/composition-api
If you have been using just@vue/composition-api and not @nuxtjs/composition-api, then things are very straightforward.
Remove Manual Registration
First, remove the plugin where you are manually registering the Composition API. Nuxt Bridge will handle this for you.plugins/composition-api.js
Auto-imports
Otherwise, there is nothing you need to do. However, if you want, you can remove your explicit imports from@vue/composition-api and rely on Nuxt Bridge auto-importing them for you.
Migrating from @nuxtjs/composition-api
Nuxt Bridge implements the Composition API slightly differently from@nuxtjs/composition-api and provides different composables (designed to be aligned with the composables that Nuxt 3 provides).
Because some composables have been removed and don’t yet have a replacement, this will be a slightly more complicated process.
Remove @nuxtjs/composition-api Module
You don’t have to immediately update your imports yet - Nuxt Bridge will automatically provide a ‘shim’ for most imports you currently have, to give you time to migrate to the new, Nuxt 3-compatible composables, with the following exceptions:Set bridge.capi
Enable Composition API support in yournuxt.config:
nuxt.config.ts
Composable Changes
useFetch
$fetchState and $fetch have been removed.
defineNuxtMiddleware
This was a type-helper stub function that is now removed. Remove thedefineNuxtMiddleware wrapper:
middleware/auth.ts
@nuxt/types:
defineNuxtPlugin
This was a type-helper stub function that is now removed. You may also keep using Nuxt 2-style plugins, by removing the function (as withdefineNuxtMiddleware).
Remove the defineNuxtPlugin wrapper:
plugins/my-plugin.ts
@nuxt/types:
useRouter and useRoute
Nuxt Bridge provides direct replacements for these composables viauseRouter and useRoute.
The only key difference is that useRoute no longer returns a computed property.
Migration Examples
Before: @nuxtjs/composition-api
After: Nuxt Bridge
State Management
With Bridge, useuseState for shared state:
Context Access
ReplaceuseContext with specific composables:
Migration Checklist
- Remove
@vue/composition-apifrom dependencies - Remove
@nuxtjs/composition-apifrom dependencies and modules - Remove manual Composition API registration
- Enable
bridge.capiinnuxt.config - Update
useFetchusage - Remove
defineNuxtMiddlewarewrappers - Remove
defineNuxtPluginwrappers - Update
useRoute(remove.value) - Replace
useContextwith specific composables - Replace
ssrRefwithuseState
Next Steps
After migrating your Composition API usage:- Configure Bridge settings
- Enable TypeScript for better type safety
- Explore other Nuxt 3 features available in Bridge