


Vue-Router implementation page is loading special effects method example
This article mainly introduces you to the example of using Vue-Router to realize the page loading special effect. The article gives detailed example code. I believe it has certain reference value for everyone. Friends in need can take a look below. Take a look.
Preface
vue-router is the official routing plug-in of Vue.js. It is deeply integrated with vue.js and is suitable for building single-page applications. Vue's single-page application is based on routing and components. Routing is used to set access paths and map paths and components. Traditional page applications use some hyperlinks to achieve page switching and jumps. In the vue-router single-page application, it is switching between paths, that is, switching of components.
If you are using Vue.js and Vue-Router to develop a single-page application. Because each page is a Vue component, you need to request data from the server and then let the Vue engine render it to the page.
For example, here is a user profile page.
The user.vue file is as follows:
<template> <p> <h2 v-text="user.name"></h2> <p v-text="user.description"></p> </p> </template> <script> export default{ data(){ return{ user: {} } } } </script>
Request data from the server during the animation transition, as follows:
<script> export default{ data(){ return{ user: {} } }, route: { data: function (transition) { this.getUserDetails(transition); } }, methods: { getUserDetails(transition) { this.$http.get('/users/' + this.$route.params.userName) .then(function (response) { this.user = response.data; transition.next(); }); } } } </script>
In this way, we can access the variable $loadingRouteData. You can hide all page elements and display a loading element, such as a logo, etc.
<p v-if="$loadingRouteData"> <p class="white-widget grey-bg author-area"> <p class="auth-info row"> <p class="timeline-wrapper"> <p class="timeline-item"> <p class="animated-background"> <p class="background-masker header-top"></p> <p class="background-masker header-left"></p> <p class="background-masker header-right"></p> <p class="background-masker header-bottom"></p> <p class="background-masker subheader-left"></p> <p class="background-masker subheader-right"></p> <p class="background-masker subheader-bottom"></p> </p> </p> </p> </p> </p> </p> <p v-if="!$loadingRouteData"> <p> <h2 v-text="user.name"></h2> <p v-text="user.description"></p> </p> </p>
For example, the style code being loaded is as follows:
.timeline-item { background: #fff; border-bottom: 1px solid #f2f2f2; padding: 25px; margin: 0 auto; } @keyframes placeHolderShimmer{ 0%{ background-position: -468px 0 } 100%{ background-position: 468px 0 } } .animated-background { animation-duration: 1s; animation-fill-mode: forwards; animation-iteration-count: infinite; animation-name: placeHolderShimmer; animation-timing-function: linear; background: #f6f7f8; background: linear-gradient(to right, #eeeeee 8%, #dddddd 18%, #eeeeee 33%); background-size: 800px 104px; height: 40px; position: relative; } .background-masker { background: #fff; position: absolute; } /* Every thing below this is just positioning */ .background-masker.header-top, .background-masker.header-bottom, .background-masker.subheader-bottom { top: 0; left: 40px; right: 0; height: 10px; } .background-masker.header-left, .background-masker.subheader-left, .background-masker.header-right, .background-masker.subheader-right { top: 10px; left: 40px; height: 8px; width: 10px; } .background-masker.header-bottom { top: 18px; height: 6px; } .background-masker.subheader-left, .background-masker.subheader-right { top: 24px; height: 6px; } .background-masker.header-right, .background-masker.subheader-right { width: auto; left: 300px; right: 0; } .background-masker.subheader-right { left: 230px; } .background-masker.subheader-bottom { top: 30px; height: 10px; } .background-masker.content-top, .background-masker.content-second-line, .background-masker.content-third-line, .background-masker.content-second-end, .background-masker.content-third-end, .background-masker.content-first-end { top: 40px; left: 0; right: 0; height: 6px; } .background-masker.content-top { height:20px; } .background-masker.content-first-end, .background-masker.content-second-end, .background-masker.content-third-end{ width: auto; left: 380px; right: 0; top: 60px; height: 8px; } .background-masker.content-second-line { top: 68px; } .background-masker.content-second-end { left: 420px; top: 74px; } .background-masker.content-third-line { top: 82px; } .background-masker.content-third-end { left: 300px; top: 88px; }
In this way, you There is the effect of Vue-Router when it is loading. You can write the above code into a separate component and reference it wherever you use it.
Finally
This is just a simple tutorial about the components loaded by Vue-Router. In fact, it can be improved in many places,
VueJobs.com
If you are a front-end engineer interested in Vue.js, you can browse this website to learn about foreign requirements for Vue developers.
For more Vue-Router implementation pages, the special effects method examples are loading. For related articles, please pay attention to the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Frequently Asked Questions and Solutions for Front-end Thermal Paper Ticket Printing In Front-end Development, Ticket Printing is a common requirement. However, many developers are implementing...

JavaScript is the cornerstone of modern web development, and its main functions include event-driven programming, dynamic content generation and asynchronous programming. 1) Event-driven programming allows web pages to change dynamically according to user operations. 2) Dynamic content generation allows page content to be adjusted according to conditions. 3) Asynchronous programming ensures that the user interface is not blocked. JavaScript is widely used in web interaction, single-page application and server-side development, greatly improving the flexibility of user experience and cross-platform development.

There is no absolute salary for Python and JavaScript developers, depending on skills and industry needs. 1. Python may be paid more in data science and machine learning. 2. JavaScript has great demand in front-end and full-stack development, and its salary is also considerable. 3. Influencing factors include experience, geographical location, company size and specific skills.

How to merge array elements with the same ID into one object in JavaScript? When processing data, we often encounter the need to have the same ID...

Discussion on the realization of parallax scrolling and element animation effects in this article will explore how to achieve similar to Shiseido official website (https://www.shiseido.co.jp/sb/wonderland/)...

Learning JavaScript is not difficult, but it is challenging. 1) Understand basic concepts such as variables, data types, functions, etc. 2) Master asynchronous programming and implement it through event loops. 3) Use DOM operations and Promise to handle asynchronous requests. 4) Avoid common mistakes and use debugging techniques. 5) Optimize performance and follow best practices.

The latest trends in JavaScript include the rise of TypeScript, the popularity of modern frameworks and libraries, and the application of WebAssembly. Future prospects cover more powerful type systems, the development of server-side JavaScript, the expansion of artificial intelligence and machine learning, and the potential of IoT and edge computing.

In-depth discussion of the root causes of the difference in console.log output. This article will analyze the differences in the output results of console.log function in a piece of code and explain the reasons behind it. �...
