vuejs / composition-api

Composition API plugin for Vue 2
https://composition-api.vuejs.org/
MIT License
4.19k stars 342 forks source link

【Bug】vue-composition-api.esm.js?a6f4:37 Uncaught Error: [vue-composition-api] must call Vue.use(VueCompositionAPI) before using any function. #621

Closed djkloop closed 3 years ago

djkloop commented 3 years ago

# I have used it first at the top of main.js, but the browser still reports an error

image

image

pikax commented 3 years ago

You're most likely using ref/reactive outside setup or before vue is initialized.

// composables/test.ts
import { ref } from '@vue/composition-api'

const store = ref({}) // <- this will cause an error, because javascript will run before vue is initialized.

function useStore(){
 return ref({}) // works if called inside of setup or after vue initialized
}
djkloop commented 3 years ago

You're most likely using ref/reactive outside setup or before vue is initialized.

// composables/test.ts
import { ref } from '@vue/composition-api'

const store = ref({}) // <- this will cause an error, because javascript will run before vue is initialized.

function useStore(){
 return ref({}) // works if called inside of setup or after vue initialized
}

you are right...

GeekyMonkey commented 3 years ago

What's the fix if I need to have a global ref variable?