Vue.js进阶【2-3-0】vue-router 传参页面传参

it2025-08-18  5

Vue.js进阶文章列表

post传参

调用方传参:name params

this.$router.push({ name: 'news', params: { userId: 123 }})

接受传递的参数:

<template> <div> this is the news page.the transform param is {{this.$route.params.userId}} </div> </template> <script> </script>

get传参

调用方传参:path query

this.$router.push({ path: '/news', query: { userId: 123 }});

查询参数其实就是在路由地址后面带上参数和传统的url参数一致的,传递参数使用query而且必须配合path来传递参数而不能用name,目标页面接收传递的参数使用query。 

接收参数如下:

<template> <div> this is the news page.the transform param is {{this.$route.query.userId}} </div> </template> <script> </script>

 

最新回复(0)