..." statement; 2. Use "this.$router.push({path: 'Page url address' })" statement.">
Vuejs method to implement page jump: 1. Use the "
... " statement; 2. Use "this .$router.push({path: 'page url address' })" statement.
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)
Usage:
demo2
demo2 demo2
demo2
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 },
/demo2/123
The "123" here is the aboveuserId
So, how to add it to the new page? How about getting the passed parameteruserId?
Usethis.$route.params.xxin themountedhook. Get the passed parameters, as follows:
mounted () { alert(this.$route.params.userId) } // 弹出123
demo2
/demo2?plan=private
(Note that there is no need to configure the path inrouter.js)
To obtain the passed address key-value pair plan in the new page, you canmountedUsethis.$route.plan.xxin the hook. Get the passed address key-value pair, as follows:
mounted () { alert(this.$route.query.plan) } // 弹出private
methods:{ toURL(){ this.$router.push({ path: '/demo2' }) } }
methods:{ toURL(){ this.$router.push({ name: 'demo2', params: { userId: 123 }}) } }
methods:{ toURL(){ this.$router.push({ name: 'demo2', params: { userId: 123 }, query: { plan: 'private' } }) } }
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!