Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to implement a loading screen for a SPA written in Vue.js?

Tags:

vue.js

vuejs2

I am new to Vue.js, coming from AngularJS 1. Does anybody have tips on how to implement a loading screen such as PleaseWait?

like image 601
tatsuhirosatou Avatar asked Mar 12 '17 05:03

tatsuhirosatou


People also ask

How do you implement lazy loading in Vue?

Vue. js handles loading components lazily with routes, so on the DOM you can load components only when they are needed through routes. This is done by splitting each route's components into chunks that are separate from the main chunk loaded on initialization.

Is Vue JavaScript a spa?

This type of application is typically referred to as a Single-Page Application (SPA). Vue provides core libraries and comprehensive tooling support with amazing developer experience for building modern SPAs, including: Client-side router. Blazing fast build tool chain.

How do you call a function on page load in Vue?

All we have to do is create a method on our component that uses the name of that lifecycle. If we wanted to call a method right when the component is created, this is how we would do that: export default { created() { console. log('Component has been created!'


1 Answers

I also created an example that integrated with PleaseWait.js

http://codepen.io/CodinCat/pen/ZeKxgK?editors=1010

Since PleaseWait.js manipulates real DOM directly, the code becomes a little bit tricky. I'd recommend to re-implement this library in Vue.js. Vue does have transitions: https://vuejs.org/v2/guide/transitions.html


You can just create a component for it, and use v-if to hide/show it

<loading-screen v-if="isLoading"></loading-screen>

A very simple example: http://codepen.io/CodinCat/pen/MpmVMp

like image 116
CodinCat Avatar answered Sep 19 '22 14:09

CodinCat