Subscribe on changes!

Using Teleport via Application API - app.teleport(...)

avatar
Oct 9th 2021

What problem does this feature solve?

In writing vue plugin, sometime it needs an extra vue component mounted on the page.

In the current situation, app.component(...) can only register the vue component but not to create it in vue plugin.

We can just const widget = createApp(...) and widget.mount('#myDiv') to mount it in the page as a separate Vue Application.

I think there shall be a better way as <Teleport> is already introduced in Vue3.

What does the proposed API look like?

This new application API shall look like app.teleport(myComp, {to: '#myDiv'})

This should be equivalent to <teleport to="#myDiv"><myComp></myComp></teleport> in SFC, but in the install(app, config){...} of vue plugin

avatar
Oct 10th 2021

Open an RFC on the rfcs repo.

BTW it should be a standalone function instead of a function attached to app for tree shaking reasons