How it works...

The syntax for asynchronous component, therefore, is as follows:

Vue.component('comp-name', (resolve, reject) => { ... })

Instead of passing an object as a second argument, we are actually passing a function with two arguments. The first is a function that you will have to call once the component (more precisely, the object that contains the properties of the component) is available. The second is another function that accepts a string. When Vue is not working in production mode, the string will be displayed in the console. You can have several reasons why the component is not working, such as an actual timeout or a connection error:

if (response.status > 400) { reject('4XX error received') } setTimeout(() => { reject('connection ...

Get Vue.js 2 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.