How it works...

The proxyTable object will configure the http-proxy-middleware. This is useful every time we are developing the UI of a bigger web application and we launch our developer server on localhost, but our API responds to another web server. This is especially relevant when we want to use CORS and we don't allow other websites to use our API. The Xkcd API doesn't allow localhost to consume the web service. This is why, even if we try to use the Xkcd API directly, our browser won't let us. The changeOrigin option will send the request with Xkcd as host, making CORS unnecessary.

To call an action from a component, we used the dispatch function. It's also possible to pass the second argument, the first being the name of the action ...

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.