question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Be able to declare async components

See original GitHub issue

Currently 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:closed
  • Created 4 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
LinusBorgcommented, Aug 27, 2019

which is analogous to

Vue.component('my-component', { /* ... */ });`

No. It’s analogous to:

Vue.extend({ /* .. */ })
  • 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 contructor

Async Components are not a different “type” of component. They are just normal components wrapped in a function that imports them via a dynamic import:

const MyAsyncComponent = () => import('./myNormalComponent')

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

0reactions
zealotrahlcommented, Jun 17, 2021

Hi all, any updates? I have a same issue…

I solved using, https://github.com/vuejs/composition-api defineAsyncComponent(() => import(@/views/${componentPath}.vue)

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found