方式一:
// 不传参
this.$router.push('路由路径')
// 如:
// this.$router.push('/search')
// 传参
this.$router.push('/路径?参数名1=参数值1&参数2=参数值2')
方式二:
// 不传参
this.$router.push({
path: '路由路径'
})
// 如:
// this.$router.push({
// path: '/search'
// })
// 传参
this.$router.push({
path: '/路径',
query: {
参数名1: '参数值1',
参数名2: '参数值2'
}
})
接收参数方式:
$route.query.参数名
// 如果js中接收需要加上this
this.$route.query.参数名
这里路由为在还是需要配置动态路由:key
path: '/search/:words?', //如果不传参数,也希望匹配,可以加个可选符 "?",如:这里的words后面的 ?
方式一:
this.$router.push('/路径/参数值')
方式二:
this.$router.push({
path: '/路径/参数值'
})
接收参数方式:
$route.params.参数名
// 如果js中接收需要加上this
this.$route.params.参数名
{ name: '路由名', path: '/path/xxx', component: XXX },
// 如:
// { name: 'searchcc', path: '/search/:words?', component: Search },
// 不传参
this.$router.push({
name: '路由名'
})
// 传参
this.$router.push({
name: '路由名字',
query: {
参数名1: '参数值1',
参数名2: '参数值2'
}
})
接收参数方式:
$route.query.参数名
// 如果js中接收需要加上this
this.$route.query.参数名
this.$router.push({
name: '路由名字',
params: {
参数名: '参数值',
}
})
接收参数方式:
$route.params.参数名
// 如果js中接收需要加上this
this.$route.params.参数名