Skip to content

getCurrentInstance does not work #267

Open
@abratko

Description

@abratko

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions