vueuse / vue-demi

🎩 Creates Universal Library for Vue 2 & 3
MIT License
3.01k stars 158 forks source link

getCurrentInstance does not work #267

Open abratko opened 3 weeks ago

abratko commented 3 weeks ago

I wrote small dependency container plugin for Vue 2.7. i need use getCurrentInstance.

It works correctly if i import one from Vue directly. But if i change import from 'vue-demi', i always get error 'Dependency container undefined. Check plugin setup'

import { getCurrentInstance } from 'vue-demi'

import { DescriptorsContainer } from './plugin/descriptors-container'

export function getContainer (): DescriptorsContainer {
  const currentInstance = getCurrentInstance()?.proxy

  // it is defined and not null if i import getCurrentInstance from  Vue  directly
  const container = currentInstance?.$vueModelerDc 

  if (!container) {
    // i alway here If getCurrentInstance  imported from vue-demi    
    throw new Error('Dependency container undefined. Check plugin setup')
  }

  return container
}

please, help me understand what is wrong