路由文件,配置动态路由( /: -后面的tabsItem为参数名称,参数名后的?号 -使参数可以为空而不报错 )
1 { 2 // 关于我们 3 path: '/home/about_us/:tabsItem?', 4 name: 'AboutUs', 5 component: () => import('/src/view/AboutUs/index.vue') 6 }
跳转路由时传参代码
1 import {useRouter} from "vue-router"; 2 const router = useRouter() 3 const menuClick = (path, data) => { 4 data ? router.push(path + '/' + data) : router.push(path) 5 }
获取动态路由传入的参数,route.params取出来的参数是一个参数对象。需要通过配置动态路由的参数名称取具体值
1 import {useRoute} from "vue-router"; 2 const route = useRoute(); 3 if(route.params && route.params.tabsItem === '1'){ 4 tabsItem.value = false 5 }
标签:传参,route,tabsItem,参数,path,router,动态,路由 From: https://www.cnblogs.com/HE0318bei/p/16792314.html