


How to use vue-route to automatically determine the left and right page turning transition animation
I made a mobile spa project some time ago. The technology is based on: vue + vue-router + vuex + mint-ui
Because the webpack template of vue-cli scaffolding is used, all pages are in .vue The file with the suffix is used as a component
The company has relatively few projects recently and finally I have time to record some of my little experience using vue-router,
General mobile port single-page application There will be a corresponding transition animation when jumping to the page, such as:
1. The transition animation that needs to be displayed when jumping from the current first-level page to the second-level page is that the first-level page moves to the left side of the screen At the same time as it disappeared,
the secondary page appeared moving from the right to the left of the screen. (Similar to the effect of turning a book to the next page)
2. The transition animation that needs to be displayed when jumping back from the current second-level page to the first-level page is to move the second-level page to the right of the screen. At the same time as it disappeared,
the first-level page appeared moving from the left to the right of the screen. Similar to (the effect of turning a book back to the previous page)
But a question arises: How to determine the hierarchical relationship between the current page and the page to be jumped?
My solution is: when creating a page (component), distinguish the components by setting the path (access path) attribute of the page in the router of the definition page hierarchical relationship between them.
For example, the access path of a first-level page (component) ‘A’ is ‘/A’. The access path of his secondary page 'B' is '/A/B' .
Then before jumping to the page, you only need to compare the current page and The path depth of the page to be jumped to can be used to dynamically set the transition animation.
For example, the depth of '/A/B' > '/A' 's depth is from the B page Jumping to the A page should be Effect 2: (The effect of turning a book back to the previous page).
1. First the parent page
home.vue:
##
scoped
.child-view { position: absolute; width: 100%; height: 100%; transition: all .5s ease; -webkit-transition: all .5s ease; -moz-transition: all .5s ease; }
<em><em><em>.rightin-enter,<br/>.leftin-leave-active {<br/> opacity: 0;<br/> transform: translate3d(50% 0, 0);<br/> -webkit-transform: translate3d(50%, 0, 0);<br/> -moz-transform: translate3d(50%, 0, 0);<br/>}<br/><br/>.leftin-enter,<br/>.rightin-leave-active {<br/> opacity: 0;<br/> transform: translate3d(-50% 0, 0);<br/> -webkit-transform: translate3d(-50%, 0, 0);<br/> -moz-transform: translate3d(-50%, 0, 0);<br/>}<br/><br/><span style="color: #0000ff;"></style></span></em></em></em>
main.js:
//进入路由之前设置拦截器let noLoginList = ["login", "register", "forget", "home", "classify", "goodsDetial"]; router.routeInfo.beforeEach((to, from, next) => { let user = sessionStorage.getItem('user'); //如果要去登录页面 if (noLoginList.indexOf(to.name) >= 0) { if (!user || user == '') { //未登录的状态通行 next(); return; } else { if (["login", "register", "forget"].indexOf(to.name) >= 0) { //已登录的状态去首页 next({ name: 'home' }); return; } else { //已登录的状态去首页 next(); return; } } } else { //去登录页面以外的页面(以下是本文关键代码) if (user && user != '') { //判断是否为需要缓存组件,如果是添加组件名到数组 if (to.meta.keepAlive) { const toName = to.name; let keepLi = store.getters.getKeepAlList; keepLi.indexOf(toName) < 0 ? keepLi.push(toName) : ''; store.commit('SET_KEEPALLIST', keepLi); } //根据路径名深度设置转场动画类型 store.commit('SET_TRANSNA', (to.path.split('/').length < from.path.split('/').length ? 'leftin' : 'rightin')); next(); } else { let toWhere = router.nameList.indexOf(to.name) >= 0 ? to : {name: 'home'}; next({ name: 'login', params: { jumpTo: { name: toWhere.name, params: toWhere.params, query: toWhere.query, }, } }); } } });
The above is the detailed content of How to use vue-route to automatically determine the left and right page turning transition animation. For more information, please follow other related articles on 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

AI Hentai Generator
Generate AI Hentai for free.

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



PHP email detection: Determine whether the email has been sent successfully. When developing web applications, you often need to send emails to communicate with users. Whether it is registration confirmation, password reset, or sending notifications, the email function is an indispensable part. However, sometimes we cannot ensure whether the email is actually sent successfully, so we need to perform email detection and determine whether the email has been sent successfully. This article will introduce how to use PHP to implement this function. 1. Use SMTP server to send emails. First, we need to use SM

Use Java's Character.isDigit() function to determine whether a character is a numeric character. Characters are represented in the form of ASCII codes internally in the computer. Each character has a corresponding ASCII code. Among them, the ASCII code values corresponding to the numeric characters 0 to 9 are 48 to 57 respectively. To determine whether a character is a number, you can use the isDigit() method provided by the Character class in Java. The isDigit() method is of the Character class

Use Java's File.isDirectory() function to determine whether a file exists and is of directory type. In Java programming, you often encounter situations where you need to determine whether a file exists and is of directory type. Java provides the File class to operate files and directories. The isDirectory() function can help us determine whether a file is a directory type. The File.isDirectory() function is a method in the File class. Its function is to determine the current File

With the development of the Internet, pictures have become an indispensable part of web pages. But as the number of images increases, the loading speed of images has become a very important issue. In order to solve this problem, many websites use thumbnails to display images, but in order to generate thumbnails, we need to use professional image processing tools, which is a very troublesome thing for some non-professionals. Then, using JavaScript to achieve automatic thumbnail generation becomes a good choice. How to use JavaS

Preface: vim is a powerful text editing tool, which is very popular on Linux. Recently, I encountered a strange problem when using vim on another server: when I copied and pasted a locally written script into a blank file on the server, automatic indentation occurred. To use a simple example, the script I wrote locally is as follows: aaabbbcccddd. When I copy the above content and paste it into a blank file on the server, what I get is: aabbbcccddd. Obviously, this is what vim does automatically for us. Format indentation. However, this automatic is a bit unintelligent. Record the solution here. Solution: Set the .vimrc configuration file in our home directory, new

If you are using a Linux operating system and want the system to automatically mount the drive on boot, you can do this by adding the device's unique identifier (UID) and mount point path to the fstab configuration file. fstab is a file system table file located in the /etc directory. It contains information about the file systems that need to be mounted when the system starts. By editing the fstab file, you can ensure that the required drives are loaded correctly every time the system starts, thus ensuring stable system operation. Automatically mounting drivers can be conveniently used in a variety of situations. For example, I plan to back up my system to an external storage device. To achieve automation, ensure that the device remains connected to the system, even at startup. Likewise, many applications will directly

How to use the isInfinite() method of the Double class to determine whether a number is infinity. In Java, the Double class is a wrapper class used to represent floating point numbers. This class provides a series of methods that can conveniently operate on floating point numbers. Among them, the isInfinite() method is used to determine whether a floating point number is infinite. Infinity refers to positive infinity and negative infinity that are so large that they exceed the range that floating point numbers can represent. In computers, the maximum value of a floating point number can be obtained through the Double class

PHP and PHPMAILER: How to implement automatic filtering of mail sending? In modern society, email has become one of the important ways for people to communicate. However, with the popularity and widespread use of email, the amount of spam has also shown an explosive growth trend. Spam emails not only waste users' time and network resources, but may also bring viruses and phishing behaviors. Therefore, when developing the email sending function, it becomes crucial to add the function of automatically filtering spam. This article will introduce how to use PHP and PHPMai
