在Vue Router中,可以使用params选项将参数传递给路由,并且这些参数不会显示在路径中。\n\n首先,在定义路由时,需要使用props: true来允许将参数作为组件的属性传递:\n\njavascript\nconst routes = [\n {\n path: '/example',\n name: 'example',\n component: ExampleComponent,\n props: true\n }\n]\n\n\n然后,在组件中,可以通过$route.params来获取传递的参数:\n\njavascript\n export default {\n name: 'ExampleComponent',\n mounted() {\n console.log(this.$route.params); // 获取传递的参数\n }\n}\n\n\n最后,在使用this.$router.push进行路由跳转时,可以将参数作为第二个参数传递:\n\njavascript\nthis.$router.push({\n name: 'example',\n params: {\n id: 1,\n name: 'example'\n }\n})\n\n\n在上面的示例中,将参数idname传递给了名为example的路由,并且这些参数不会显示在路径中。在ExampleComponent组件中,可以通过this.$route.params获取到传递的参数。

Vue Router 路由传参:隐藏参数在URL中

原文地址: https://www.cveoy.top/t/topic/qFy1 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录