Use Vue Composition API globally
npm install vue-global-apiUse Vue Composition API globally
Instead of import APIs from vue in every file,
``html`
Now you can directly use them everywhere (with TypeScript support!)
`html`
`bash`
npm i vue-global-api
Then import vue-global-api in your main entry to register the global apis before any usages
`ts`
// main.js
import 'vue-global-api'
And enjoy :)
By default, importing vue-global-api will register all common composition apis to the global object. If you want to have fine-grain control, use submodule per API:
`tsref
// only register and computed as global APIs`
import 'vue-global-api/ref'
import 'vue-global-api/computed'
We have provided a few sub-set collections if you want to control the global API registration by their type.
`tsref
// register all reactivity apis (, computed, watch, etc.)onMounted
import 'vue-global-api/reactivity'
// register all lifecycle hooks (, onUpdated, onUnmounted, etc.)inject
import 'vue-global-api/lifecycle'
// register component apis (, provide, h, etc.)`
import 'vue-global-api/component'
If you want to have global api work in CDN, you don't actually need this package. All you need to do is:
`ts`
Object.assign(window, Vue)
In the latest