$router和$route的区别

    技术2024-01-04  104

    在vue2.0里页面参数是 this. r o u t e . q u e r y 或 者 t h i s . route.query或者 this. route.querythis.route.params 接收router-link传的参数。

    在路由跳转的时候除了用router-link标签以外需要在script标签在事件里面跳转,所以有个方法就是在script标签里面写this.$router.push(‘要跳转的路径名’),

    在写的时候发现这两个为什么不同,在控制台打出this的时候,发现 r o u t e 和 route和 routerouter同时存在

    $route为当前router跳转对象里面可以获取name、path、query、params等

    r o u t e r 为 V u e R o u t e r 实 例 , 想 要 导 航 到 不 同 U R L , 则 使 用 router为VueRouter实例,想要导航到不同URL,则使用 routerVueRouterURL使router.push方法

    返回上一个history也是使用$router.go方法

    Processed: 0.016, SQL: 9