@vue/composition-api vs @nuxtjs/composition-api vs @vueuse/integrations
Vue Composition API Support and Integration Utilities
@vue/composition-api@nuxtjs/composition-api@vueuse/integrations

Vue Composition API Support and Integration Utilities

@vue/composition-api and @nuxtjs/composition-api were critical bridges that enabled Composition API syntax in Vue 2 and Nuxt 2 projects before native support existed. @vueuse/integrations is a modern utility collection designed for Vue 2.7+ and Vue 3, providing pre-built composables for third-party libraries. While the first two packages solve framework compatibility issues for legacy systems, the latter focuses on enhancing developer productivity in maintained environments.

Npm Package Weekly Downloads Trend

3 Years

Github Stars Ranking

Stat Detail

Package
Downloads
Stars
Size
Issues
Publish
License
@vue/composition-api125,0594,176407 kB03 years agoMIT
@nuxtjs/composition-api31,877702100 kB423 years agoMIT
@vueuse/integrations022,399149 kB4042 months agoMIT

Vue Composition API Support and Integration Utilities Compared

Understanding the evolution of Composition API support is critical when managing Vue ecosystems. @vue/composition-api and @nuxtjs/composition-api were essential tools during the Vue 2 era, while @vueuse/integrations represents the modern standard for utilities in Vue 3 and Vue 2.7+. Let's break down how they differ in setup, usage, and long-term viability.

🛠️ Core Purpose & Version Support

@vue/composition-api brings Composition API to Vue 2 versions prior to 2.7.

  • It acts as a plugin to polyfill setup, ref, reactive, and other APIs.
  • Required for Vue 2.0 – 2.6.
// @vue/composition-api: Plugin installation
import Vue from 'vue';
import VueCompositionAPI from '@vue/composition-api';

Vue.use(VueCompositionAPI);

@nuxtjs/composition-api extends Composition API support specifically for Nuxt 2.

  • It wraps Nuxt 2 context (store, route, params) for use in setup.
  • Required for Nuxt 2 projects using Composition API syntax.
// @nuxtjs/composition-api: Nuxt module config
// nuxt.config.js
export default {
  buildModules: ['@nuxtjs/composition-api/module']
}

@vueuse/integrations provides utilities for Vue 2.7+ and Vue 3.

  • It assumes Composition API is already available (native or polyfilled).
  • Focuses on third-party library wrappers, not core API support.
// @vueuse/integrations: Direct import
import { useAxios } from '@vueuse/integrations/useAxios';
import axios from 'axios';

⚙️ Setup & Configuration

@vue/composition-api requires manual plugin registration.

  • You must install it before creating the Vue instance.
  • Failing to register it causes runtime errors when using setup.
// @vue/composition-api: Main entry
import Vue from 'vue';
import App from './App.vue';
import VueCompositionAPI from '@vue/composition-api';

Vue.use(VueCompositionAPI);
new Vue({ render: h => h(App) }).$mount('#app');

@nuxtjs/composition-api uses Nuxt's module system.

  • Add it to buildModules in your config file.
  • Automatically handles server-side rendering compatibility.
// @nuxtjs/composition-api: Component usage
export default defineComponent({
  setup() {
    const { app } = useContext();
    // Access Nuxt context safely
  }
})

@vueuse/integrations requires no global setup.

  • Import specific functions where needed.
  • Works tree-shakably with bundlers like Vite or Webpack.
// @vueuse/integrations: Composable usage
export default {
  setup() {
    const { data, loading } = useAxios('/api/users');
    return { data, loading };
  }
}

🔄 Accessing Context & State

@vue/composition-api relies on standard Vue 2 instance properties.

  • You access data via this in Options API or setup return.
  • No built-in helpers for router or store without extra plugins.
// @vue/composition-api: Standard setup
export default {
  setup() {
    const count = ref(0);
    return { count };
  }
}

@nuxtjs/composition-api provides specific hooks for Nuxt context.

  • useContext, useStore, and useRoute abstract Nuxt 2 internals.
  • Essential for accessing server-side data in setup.
// @nuxtjs/composition-api: Nuxt context
export default defineComponent({
  setup() {
    const { store } = useContext();
    const user = computed(() => store.state.user);
    return { user };
  }
})

@vueuse/integrations focuses on external service state.

  • Manages state for libraries like Axios, Focus Trap, or Cookies.
  • Does not manage framework context directly.
// @vueuse/integrations: External state
export default {
  setup() {
    const { data, isFinished } = useAxios('https://api.example.com/data');
    return { data, isFinished };
  }
}

⚠️ Deprecation & Migration Path

@vue/composition-api is legacy for Vue 2 < 2.7.

  • Vue 2.7+ includes Composition API natively.
  • Vue 3 has it built-in by default.
  • Do not use in new projects. Migrate to Vue 3 or Vue 2.7.
// Migration: Vue 2.7+ or Vue 3 (No plugin needed)
import { ref } from 'vue';

export default {
  setup() {
    const count = ref(0);
    return { count };
  }
}

@nuxtjs/composition-api is legacy for Nuxt 2.

  • Nuxt 3 uses Vue 3 native Composition API.
  • Nuxt 2 is in maintenance mode only.
  • Do not use for new applications. Plan migration to Nuxt 3.
// Migration: Nuxt 3 (Native support)
// components/Example.vue
<script setup>
const { $store } = useNuxtApp();
const user = computed(() => $store.state.user);
</script>

@vueuse/integrations is actively maintained.

  • Regular updates for Vue 3 and Vue 2.7 compatibility.
  • Safe for long-term use in modern stacks.
  • Recommended for all new Vue projects needing integrations.
// Modern Standard: VueUse Integrations
import { useAxios } from '@vueuse/integrations';

export default {
  setup() {
    const { data } = useAxios('/api/data');
    return { data };
  }
}

📊 Summary: Key Differences

Feature@vue/composition-api@nuxtjs/composition-api@vueuse/integrations
Target VersionVue 2.0 – 2.6Nuxt 2Vue 2.7+ & Vue 3
Primary GoalPolyfill Composition APINuxt 2 Context SupportThird-Party Integrations
Setup RequiredYes (Vue.use)Yes (Nuxt Module)No (Import only)
MaintenanceLegacy / EOLLegacy / Maintenance ModeActive
New Projects❌ Avoid❌ Avoid✅ Recommended

💡 The Big Picture

@vue/composition-api and @nuxtjs/composition-api were vital during the transition from Vue 2 Options API to Composition API. They allowed teams to adopt modern patterns before the core framework supported them. However, with Vue 2 reaching End of Life and Nuxt 3 stabilizing, these packages are now legacy tools. Use them only to keep existing systems running while you plan a migration.

@vueuse/integrations is the forward-looking choice. It assumes you are on a supported Vue version and helps you connect your app to the wider ecosystem without reinventing the wheel. It reduces boilerplate for common tasks like HTTP requests, focus management, and authentication.

Final Thought: If you are starting fresh, build on Vue 3 or Vue 2.7+ with @vueuse/integrations. Reserve the older packages strictly for maintaining existing Vue 2 or Nuxt 2 codebases until migration is complete.

How to Choose: @vue/composition-api vs @nuxtjs/composition-api vs @vueuse/integrations

  • @vue/composition-api:

    Select this solely for legacy Vue 2 projects running versions below 2.7. It polyfills the Composition API for older Vue 2 cores. For Vue 2.7+ or Vue 3, this package is unnecessary because the API is built-in.

  • @nuxtjs/composition-api:

    Choose this only if you are maintaining an existing Nuxt 2 project that cannot yet migrate to Nuxt 3. It provides access to Nuxt context within the Composition API. Do not use this for new projects, as Nuxt 3 includes native support.

  • @vueuse/integrations:

    Use this for modern Vue 3 or Vue 2.7+ applications that need reliable integrations with external libraries like Axios, Focus Trap, or JWT. It is actively maintained and works seamlessly with the native Composition API.

README for @vue/composition-api

@vue/composition-api

Vue 2 plugin for Composition API

npm GitHub Workflow Status Minzipped size

English | 中文 ・ Composition API Docs

⚠️ With the release of Vue 2.7, which has Composition API built-in, you no longer need this plugin. Thereby this plugin has entered maintenance mode and will only support Vue 2.6 or earlier. This project will reach End of Life by the end of 2022.

Installation

NPM

npm install @vue/composition-api
# or
yarn add @vue/composition-api

You must install @vue/composition-api as a plugin via Vue.use() before you can use the Composition API to compose your component.

import Vue from 'vue'
import VueCompositionAPI from '@vue/composition-api'

Vue.use(VueCompositionAPI)
// use the APIs
import { ref, reactive } from '@vue/composition-api'

:bulb: When you migrate to Vue 3, just replacing @vue/composition-api to vue and your code should just work.

CDN

Include @vue/composition-api after Vue and it will install itself automatically.

<script src="https://cdn.jsdelivr.net/npm/[email protected]"></script>
<script src="https://cdn.jsdelivr.net/npm/@vue/[email protected]"></script>

@vue/composition-api will be exposed to global variable window.VueCompositionAPI.

const { ref, reactive } = VueCompositionAPI

TypeScript Support

TypeScript version >4.2 is required

To let TypeScript properly infer types inside Vue component options, you need to define components with defineComponent

import { defineComponent } from '@vue/composition-api'

export default defineComponent({
  // type inference enabled
})

JSX/TSX

JSX is now officially supported on vuejs/jsx. You can enable it by following this document. A community maintained version can be found at babel-preset-vca-jsx by @luwanquan.

To support TSX, create a declaration file with the following content in your project.

// file: shim-tsx.d.ts
import Vue, { VNode } from 'vue';
import { ComponentRenderProxy } from '@vue/composition-api';

declare global {
  namespace JSX {
    interface Element extends VNode {}
    interface ElementClass extends ComponentRenderProxy {}
    interface ElementAttributesProperty {
      $props: any; // specify the property name to use
    }
    interface IntrinsicElements {
      [elem: string]: any;
    }
  }
}

SSR

Even if there is no definitive Vue 3 API for SSR yet, this plugin implements the onServerPrefetch lifecycle hook that allows you to use the serverPrefetch hook found in the classic API.

import { onServerPrefetch } from '@vue/composition-api'

export default {
  setup(props, { ssrContext }) {
    const result = ref()

    onServerPrefetch(async () => {
      result.value = await callApi(ssrContext.someId)
    })

    return {
      result,
    }
  }
}

Browser Compatibility

@vue/composition-api supports all modern browsers and IE11+. For lower versions IE you should install WeakMap polyfill (for example from core-js package).

Limitations

:white_check_mark: Support     :x: Not Supported

Ref Unwrap

❌ Should NOT use ref in a plain object when working with Array
const a = {
  count: ref(0),
}
const b = reactive({
  list: [a], // `a.count` will not unwrap!!
})

// no unwrap for `count`, `.value` is required
b.list[0].count.value === 0 // true
const b = reactive({
  list: [
    {
      count: ref(0), // no unwrap!!
    },
  ],
})

// no unwrap for `count`, `.value` is required
b.list[0].count.value === 0 // true
✅ Should always use ref in a reactive when working with Array
const a = reactive({
  list: [
    reactive({
      count: ref(0),
    }),
  ]
})
// unwrapped
a.list[0].count === 0 // true

a.list.push(
  reactive({
    count: ref(1),
  })
)
// unwrapped
a.list[1].count === 1 // true

Template Refs

✅ String ref && return it from setup()
<template>
  <div ref="root"></div>
</template>

<script>
  export default {
    setup() {
      const root = ref(null)

      onMounted(() => {
        // the DOM element will be assigned to the ref after initial render
        console.log(root.value) // <div/>
      })

      return {
        root,
      }
    },
  }
</script>
✅ String ref && return it from setup() && Render Function / JSX
export default {
  setup() {
    const root = ref(null)

    onMounted(() => {
      // the DOM element will be assigned to the ref after initial render
      console.log(root.value) // <div/>
    })

    return {
      root,
    }
  },
  render() {
    // with JSX
    return () => <div ref="root" />
  },
}
❌ Function ref
<template>
  <div :ref="el => root = el"></div>
</template>

<script>
  export default {
    setup() {
      const root = ref(null)

      return {
        root,
      }
    },
  }
</script>
❌ Render Function / JSX in setup()
export default {
  setup() {
    const root = ref(null)

    return () =>
      h('div', {
        ref: root,
      })

    // with JSX
    return () => <div ref={root} />
  },
}
⚠️ $refs accessing workaround

:warning: Warning: The SetupContext.refs won't exist in Vue 3.0. @vue/composition-api provide it as a workaround here.

If you really want to use template refs in this case, you can access vm.$refs via SetupContext.refs

export default {
  setup(initProps, setupContext) {
    const refs = setupContext.refs
    onMounted(() => {
      // the DOM element will be assigned to the ref after initial render
      console.log(refs.root) // <div/>
    })

    return () =>
      h('div', {
        ref: 'root',
      })

    // with JSX
    return () => <div ref="root" />
  },
}

Reactive

⚠️ reactive() mutates the original object

reactive uses Vue.observable underneath which will mutate the original object.

:bulb: In Vue 3, it will return a new proxy object.

⚠️ set and del workaround for adding and deleting reactive properties

⚠️ Warning: set and del do NOT exist in Vue 3. We provide them as a workaround here, due to the limitation of Vue 2.x reactivity system.

In Vue 2, you will need to call set to track new keys on an object(similar to Vue.set but for reactive objects created by the Composition API). In Vue 3, you can just assign them like normal objects.

Similarly, in Vue 2 you will need to call del to ensure a key deletion triggers view updates in reactive objects (similar to Vue.delete but for reactive objects created by the Composition API). In Vue 3 you can just delete them by calling delete foo.bar.

import { reactive, set, del } from '@vue/composition-api'

const a = reactive({
  foo: 1
})

// add new reactive key
set(a, 'bar', 1)

// remove a key and trigger reactivity
del(a, 'bar')

Watch

❌ onTrack and onTrigger are not available in WatchOptions
watch(() => {
    /* ... */
}, {
  immediate: true,
  onTrack() {}, // not available
  onTrigger() {}, // not available
})

createApp

⚠️ createApp() is global

In Vue 3, createApp() is introduced to provide context(plugin, components, etc.) isolation between app instances. Due the design of Vue 2, in this plugin, we provide createApp() as a forward compatible API which is just an alias of the global.

const app1 = createApp(RootComponent1)
app1.component('Foo', Foo) // equivalent to Vue.component('Foo', Foo)
app1.use(VueRouter) // equivalent to Vue.use(VueRouter)

const app2 = createApp(RootComponent2)
app2.component('Bar', Bar) // equivalent to Vue.component('Bar', Bar)

createElement / h

⚠️ createElement / h workaround

createElement / h in Vue 2 is only accessable in render() function. To use it outside of render(), you can explicitly bind a component instance to it.

:warning: Warning: This ability is provided as a workaround Vue 2, it's not part of the Vue 3 API.

import { h as _h } from '@vue/composition-api'

export default {
  setup() {
    const vm = getCurrentInstance()
    const h = _h.bind(vm)

    return () =>
      h('div', {
        ref: 'root',
      })
  },
}

shallowReadonly

⚠️ shallowReadonly() will create a new object and with the same root properties, new properties added will not be readonly or reactive.

:bulb: In Vue 3, it will return a new proxy object.

readonly

⚠️ readonly() provides only type-level readonly check.

readonly() is provided as API alignment with Vue 3 on type-level only. Use isReadonly() on it or it's properties can not be guaranteed.

props

⚠️ toRefs(props.foo) will incorrectly warn when accessing nested levels of props.
    ⚠️ isReactive(props.foo) will return false.
defineComponent({
  setup(props) {
    const { bar } = toRefs(props.foo) // it will `warn`

    // use this instead
    const { foo } = toRefs(props)
    const a = foo.value.bar
  }
})

computed().effect

⚠️ computed() has a property effect set to true instead of a ReactiveEffect.

Due to the difference in implementation, there is no such concept as a ReactiveEffect in @vue/composition-api. Therefore, effect is merely true to enable differentiating computed from refs:

function isComputed<T>(o: ComputedRef<T> | unknown): o is ComputedRef<T>
function isComputed(o: any): o is ComputedRef {
  return !!(isRef(o) && o.effect)
}

Missing APIs

The following APIs introduced in Vue 3 are not available in this plugin.

  • onRenderTracked
  • onRenderTriggered
  • isProxy

Reactive APIs in data()

❌ Passing ref, reactive or other reactive apis to data() would not work.
export default {
  data() {
    return {
      // will result { a: { value: 1 } } in template
      a: ref(1),
    }
  },
}

emits Options

❌ emits option is provided in type-level only, in order to align with Vue 3's type interface. Does NOT have actual effects on the code.
defineComponent({
  emits: {
    // has no effects
    submit: (eventOption) => {
      if (...) {
        return true
      } else {
        console.warn('Invalid submit event payload!')
        return false
      }
    }
  }
})

Performance Impact

Due the limitation of Vue2's public API. @vue/composition-api inevitably introduces some performance overhead. Note that in most scenarios, this shouldn't be the source of performance issues.

You can check the benchmark results for more details.