Home >Web Front-end >JS Tutorial >Other operations for Vue.js routing

Other operations for Vue.js routing

php中世界最好的语言
php中世界最好的语言Original
2018-03-13 14:41:281301browse

This time I will bring you other operations of Vue.jsrouting, what are the precautions for using other operations of Vue.js routing, the following is a practical case, let’s take a look one time.

Based on the current path, jump to apple

   <router-link to="apple">to apple</router-link>
    上面的和下面的区别    <router-link :to="{path:&#39;banana&#39;}">to banana</router-link>

If you want to jump to the root directory, add /

   <router-link to="/apple">to apple</router-link>
    上面的和下面的区别    <router-link :to="{path:&#39;banana&#39;}">to banana</router-link>

If bound, we can also dynamically Modify path

<template>
  <div id="app">
    <router-link :to="path">to apple</router-link>
    ......  </div></template><script>
  export default {
    data () {      return {        path: &#39;apple&#39;
      }
    }
  }</script>

If you bind it and don’t want to modify the path dynamically, we can also write it directly.

Note: apple must be enclosed in single quotes, otherwise it will go to data When searching for apple, an error of not finding object

<router-link :to="&#39;apple&#39;">to apple</router-link>

can also be passed. You can also pass the parameter

<router-link :to="{path:&#39;banana&#39;,param:{color:&#39;yellow&#39;}}">to banana</router-link>

through tag to change the link into a li tag. Of course, you can also set the variable. Into other tags

<router-link :to="&#39;apple&#39;" tag="li">to apple</router-link>

*The above are all declarativeNavigation
Let’s experience the programmatic navigation
You can jump to a specific page through push

router.push(&#39;apple&#39;)
或者
router.push({path: &#39;apple&#39;})
或者name
......

Application scenario:
Whenever we switch routes, set some operations for him

For example: check the user's login status, if the user is not logged in, jump to it through programmatic navigation Login interface
router.beforeEach(router.push('Login interface'))

I believe you have mastered the method after reading the case in this article. Please come for more exciting information. Pay attention to other related articles on php Chinese website!

Recommended reading:

Vue tag attributes and conditional rendering of Vue.js

List rendering v of Vue.js -for array object subcomponent

What are the precautions for using Vue.js

The above is the detailed content of Other operations for Vue.js routing. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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