Closed LancerComet closed 2 years ago
This package didn't come with the function expose, but the way to implement it is quite straightforward:
expose
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?
Stale issue message
Since Vue 2.7 has its expose function, this issue has became unnecessary, closed.
It's still useful since @vue/composition-api is inherently for Vue 2.6.
@vue/composition-api
This package didn't come with the function
expose
, but the way to implement it is quite straightforward: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?