in VueJS by
How to use composition API in Vue2.0?

1 Answer

0 votes
by

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,

  1. Run the below commands to install

    npm install @vue/composition-api
    # or
    yarn add @vue/composition-api
  2. After that import this API in your main.js file,

    import Vue from 'vue'
    import VueCompositionAPI from '@vue/composition-api'
    
    Vue.use(VueCompositionAPI)
  3. Now your project is able to use composition API

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