About expose
LancerComet opened this issue · comments
LancerComet commented
This package didn't come with the function expose
, but the way to implement it is quite straightforward:
const expose = (exposing: Record<string, any>) => {
const instance = getCurrentInstance()
if (!instance) {
throw new Error('expose should be called in setup().')
}
const keys = Object.keys(exposing)
keys.forEach(key => {
instance.proxy[key] = exposing[key]
})
onBeforeUnmount(() => {
keys.forEach(key => {
instance.proxy[key] = undefined
})
})
}
const App = defineComponent({
setup () {
expose({
greet: () => console.log('Greeting')
})
return () => (
<div>Something</div>
)
}
})
Because using composition API doesn't need to take care of context and responsiveness, I think it is okay to assign functions to the instance directly, and it turns out it works quite well. So how about adding it back?
github-actions commented
Stale issue message
LancerComet commented
Since Vue 2.7 has its expose function, this issue has became unnecessary, closed.
Cloyd Lau commented
It's still useful since @vue/composition-api
is inherently for Vue 2.6.