f / vue-wait

Complex Loader and Progress Management for Vue/Vuex and Nuxt Applications
MIT License
2k stars 100 forks source link

Vue3 Composition API? #129

Open limsocheat opened 1 year ago

limsocheat commented 1 year ago

Is there any document for Vue3 Composition API?

pirhoo commented 2 months ago

As far as I know there is no composable for vue wait but you can create one easily:

import { getCurrentInstance } from 'vue'

export function useWait() {
  const instance = getCurrentInstance()
  // If `getCurrentInstance` is called outside of a Vue component setup function, it will return `null`.
  if (!instance) {
    throw new Error('useCore must be called within a Vue component setup function.')
  }
  // The `instance` object has a `proxy` property, which is the component's public instance.
  const { proxy } = instance
  // `proxy.$wait` gives us access to the global `$wait` object provided by vue-wait 
  return proxy.$wait
}

Then to use it:

const wait = useWait()
wait.start('loader name')