Home Web Front-end JS Tutorial How to use vue-route to automatically determine the left and right page turning transition animation

How to use vue-route to automatically determine the left and right page turning transition animation

Oct 12, 2017 am 10:05 AM
judgment automatic

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
Copy after login
.child-view {
 position: absolute;
 width: 100%;
 height: 100%;
 transition: all .5s ease;
 -webkit-transition: all .5s ease;
 -moz-transition: all .5s ease;
}
Copy after login
<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>
Copy after login

two. Secondly, I attach my main.js fragment (used to dynamically set the transition animation before jumping to the page)

 

main.js:


//进入路由之前设置拦截器let noLoginList = ["login", "register", "forget", "home", "classify", "goodsDetial"];
router.routeInfo.beforeEach((to, from, next) => {
  let user = sessionStorage.getItem(&#39;user&#39;);  //如果要去登录页面
  if (noLoginList.indexOf(to.name) >= 0) {    if (!user || user == &#39;&#39;) {      //未登录的状态通行      next();      return;
    } else {      if (["login", "register", "forget"].indexOf(to.name) >= 0) {        //已登录的状态去首页        next({
          name: &#39;home&#39;
        });        return;
      } else {        //已登录的状态去首页        
      next();        
      return;
      }
    }
  } else {    //去登录页面以外的页面(以下是本文关键代码)
    if (user && user != &#39;&#39;) {      //判断是否为需要缓存组件,如果是添加组件名到数组
      if (to.meta.keepAlive) {
        const toName = to.name;
        let keepLi = store.getters.getKeepAlList;
        keepLi.indexOf(toName) < 0 ? keepLi.push(toName) : &#39;&#39;;
        store.commit(&#39;SET_KEEPALLIST&#39;, keepLi);
      }      //根据路径名深度设置转场动画类型
      store.commit(&#39;SET_TRANSNA&#39;, (to.path.split(&#39;/&#39;).length < from.path.split(&#39;/&#39;).length ? &#39;leftin&#39; : &#39;rightin&#39;));
      next();
    } else {
      let toWhere = router.nameList.indexOf(to.name) >= 0 ? to : {name: &#39;home&#39;};
      next({
        name: &#39;login&#39;,
        params: {
          jumpTo: {
            name: toWhere.name,
            params: toWhere.params,
            query: toWhere.query,
          },
        }
      });
    }
  }
});
Copy after login

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!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP email detection: Determine whether the email has been sent successfully. PHP email detection: Determine whether the email has been sent successfully. Sep 19, 2023 am 09:16 AM

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 number Use java's Character.isDigit() function to determine whether a character is a number Jul 27, 2023 am 09:32 AM

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 the file exists and is a directory type Use java's File.isDirectory() function to determine whether the file exists and is a directory type Jul 24, 2023 pm 06:57 PM

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

Linux Tips: Cancel automatic indentation when pasting in vim Linux Tips: Cancel automatic indentation when pasting in vim Mar 07, 2024 am 08:30 AM

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

Automatic thumbnail generation using JavaScript Automatic thumbnail generation using JavaScript Jun 16, 2023 pm 12:51 PM

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

How to use the isInfinite() method of the Double class to determine whether a number is infinite How to use the isInfinite() method of the Double class to determine whether a number is infinite Jul 24, 2023 am 10:10 AM

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

Automount drives on Linux Automount drives on Linux Mar 20, 2024 am 11:30 AM

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

PHP and PHPMAILER: How to implement automatic filtering of mail sending? PHP and PHPMAILER: How to implement automatic filtering of mail sending? Jul 21, 2023 am 09:25 AM

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

See all articles