..." statement; 2. Use "this.$router.push({path: 'Page url address' })" statement."> How to implement page jump in vuejs-Vue.js-php.cn
Home> Web Front-end> Vue.js> body text

How to implement page jump in vuejs

青灯夜游
Release: 2021-09-28 14:44:12
Original
14767 people have browsed it

Vuejs method to implement page jump: 1. Use the " ... " statement; 2. Use "this .$router.push({path: 'page url address' })" statement.

How to implement page jump in vuejs

The operating environment of this tutorial: windows7 system, vue2.9.6 version, DELL G3 computer.

Two ways for Vue routing to implement page jumps (router-link and JS)

1. Through Implementation

The component is used to set a navigation link and switch different HTML content

Usage:

  • Simple writing method

demo2
Copy after login
  • ##Using v-bind writing method

demo2  demo2
Copy after login
  • How to write parameters

demo2
Copy after login
Passing parameters here needs to be done in

router.js Configure the path of demo2 in, and add the wildcard after demo2 in the path: and the correspondinguserId, as follows:

{ path: '/demo2/:userId', name: 'demo2', component: demo2 },
Copy after login
After the configuration is completed, the page The result of the jump is

/demo2/123

The "123" here is the above

userId

So, how to add it to the new page? How about getting the passed parameter

userId?

Use

this.$route.params.xxin themountedhook. Get the passed parameters, as follows:

mounted () { alert(this.$route.params.userId) } // 弹出123
Copy after login
  • Incoming address key-value pair

demo2
Copy after login
The page jump result is

/demo2?plan=private

(Note that there is no need to configure the path in

router.js)

To obtain the passed address key-value pair plan in the new page, you can

mountedUsethis.$route.plan.xxin the hook. Get the passed address key-value pair, as follows:

mounted () { alert(this.$route.query.plan) } // 弹出private
Copy after login
2, Implemented through JS ---this.$router.push()


template part:

Copy after login
script part:

(Note Here is router, above is route)

  • Simple writing method

methods:{ toURL(){ this.$router.push({ path: '/demo2' }) } }
Copy after login
  • Passing parameters Writing method

methods:{ toURL(){ this.$router.push({ name: 'demo2', params: { userId: 123 }}) } }
Copy after login
  • Incoming address key-value pair

methods:{ toURL(){ this.$router.push({ name: 'demo2', params: { userId: 123 }, query: { plan: 'private' } }) } }
Copy after login
Related recommendations :《

vue.js tutorial

The above is the detailed content of How to implement page jump in vuejs. 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