Complete Vue.js 2 Web Development_ Practical guide to building end-to-end web development solutions with Vue.js 2

(singke) #1
Single Page Applications Chapter 15

The next (false) command will make the user stay where they are, and we also edited the


endpoint to example.com, which will return an error code on a POST request:


How it works...


Axios will receive an error from example.com and this will trigger a rejection of the


promise created when we called post. The rejection of a promise will, in turn, trigger the


function passed inside the catch.


It's worth noting that at this point in the code, vm is referring to the root Vue instance; this is


because the code is always executed after the Vue instance is initialized and assigned to vm.


Adding a progress bar to load pages


It's true that with an SPA the user does not have to wait for a new page to load, but he still


has to wait for the data to load. In the Fetching data before switching route recipe, we had to
wait a while longer after we clicked on the button to the /aboutme page. There was


nothing to suggest that the data was loading, and then suddenly the page appeared.
Wouldn't it be great if the user had at least some feedback that the page is loading?


Getting ready


In order to follow along, you should complete the Fetching data before switching route recipe.


This recipe will build up on top of it and I'll assume that you have all the relevant code in
place already.

Free download pdf