Be able to declare async components
See original GitHub issueCurrently I can declare a component like
@Component()
export default class MyComponent extends Vue {
}
which is analogous to
Vue.component('my-component', { /* ... */ });
However if I wish to create an Async Component there is currently no way to declare it.
What I would expect to see (as a new player) is something like
@AsyncComponent({
init: doSomethingThatReturnsAPromise()
})
export default class MyComponent extends Vue {
}
or maybe have the init function be a static member on the class (my preference)
@AsyncComponent()
export default class MyComponent extends Vue {
public static defininition(): Promise {
// return a promise that does some async thing and resolves
}
}
Issue Analytics
- State:
- Created 4 years ago
- Comments:8 (2 by maintainers)
Top Results From Across the Web
Async components
The mental model of React Async is component-first. ... The easiest way to create an async component for data fetching is through the...
Read more >Async Components - Vue.js
As you can see, defineAsyncComponent accepts a loader function that returns a Promise. The Promise's resolve callback should be called when you have...
Read more >How to declare `async` functional component in react?
How to declare `async` functional component in react? ... I am trying to load the image in typescript. but not works. what is...
Read more >async function - JavaScript - MDN Web Docs - Mozilla
The async function declaration declares an async function where the await keyword is permitted within the function body. The async and await ......
Read more >Correctly handling async/await in React components
Async /await in components is a bugfest. Components have props/state that change over time. The async/await model doesn't offer a way to ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
No. It’s analogous to:
Vue.extend()
returns a new Vue constrcutor with the provided options as defaults (a “component”)Vue.component()
registers a new component globally with the main Vue contructorAsync Components are not a different “type” of component. They are just normal components wrapped in a function that imports them via a dynamic import:
So you can’t really create an async component with a decorator or anything. you have to create a normal component in its own file and then import it as an async compont by wrapping it in such a function.
And it doesn’t matter if you use vue-class-component or not.
You can find documentation about this here: https://vuejs.org/v2/guide/components-dynamic-async.html#Async-Components
I solved using, https://github.com/vuejs/composition-api defineAsyncComponent(() => import(
@/views/${componentPath}.vue
)