Home > Web Front-end > JS Tutorial > Routing parameters for Vue.js

Routing parameters for Vue.js

php中世界最好的语言
Release: 2018-03-13 14:38:08
Original
1514 people have browsed it

This time I will bring you the routing parameters of Vue.js. What are the precautions when using the routing parameters of Vue.js? The following is a practical case. Let’s take a look. .

Function: Pass routing parameters for the page.

Configure the parameters that need to be passed in the routing mapping table:
For example: apple page, I need to pass a color parameter, You can set parameters in the path starting with:.

path: '/apple/:color',
Copy after login

Specific use:

let router = new VRouter({ // 如果mode设为history, 那么地址就可以不使用哈希(# 哈希)了,就可以直接访问. http://localhost:8080/#/apple ==>> http://localhost:8080/apple
  mode: 'history',  routes: [    //  做一个映射表
    {      path: '/apple/:color',      component: Apple
    },
    {      path: '/banana',      component: Banana
    }
  ]
})
Copy after login

When I jump on the page, I splice the parameters directly after the address. The red below is what is passed The color parameter

http://localhost:8080/apple/red
Copy after login

gets the parameters passed by the page in the script tag, and gets

through the global

object

of this.$route.params. The above print result is:

{color: "red"}

To use the parameters passed by the interface in the template tag, you can use $route.params.color

<template>
  <div class="hello">
    <h1>{{msg}}</h1>
    <p>{{$route.params.color}}</p>
    <button @click="getParams">get params</button>
  </div></template>
Copy after login

Routing parameters for Vue.js

Pass multiple parameters

The routing settings are as follows:

path: &#39;/apple/:color/detail/:type&#39;,
Copy after login

The url of the passed parameters:

http://localhost:8080/apple/red/detail/3
Copy after login

Print all parameters passed:

{color: "red", type: "3"}
Copy after login

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to php Chinese website Other related articles!

Recommended reading:

Vue tag attributes and conditional rendering of Vue.js

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

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

Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template