Even though the Composition API is a part of Vue 3, it has been made available for Vue 2 as well by installing @vue/composition-api
as a plugin via Vue.use()
.
Let's see the usage in step by step instructions,
Run the below commands to install
npm install @vue/composition-api
# or
yarn add @vue/composition-api
After that import this API in your main.js file,
import Vue from 'vue'
import VueCompositionAPI from '@vue/composition-api'
Vue.use(VueCompositionAPI)
Now your project is able to use composition API
// use the APIs
import { ref, reactive } from '@vue/composition-api'