vue中this.$router.push路由2種傳參以及獲取方法
阿新 • • 發佈:2018-11-05
vue中this.$router.push路由2種傳參以及獲取方法
專案中通過this.$router.push路由跳轉頁面傳遞引數的方式很常見,一般有兩種方式:
1.params傳參:
this.$router.push({name:'parasetEdit',params:{pk_refinfo:'test',value:'test1'}});
目標頁面接收引數:
this.$route.params.pk_refinfo
2.query傳參:
this.$router.push({path:'/uapbd/paraset/edit',query:{pk_refinfo:'test',value:'test1'}});
目標頁面接收引數:
this.$route.query.pk_refinfo
兩種方式的區別是query傳參的引數會帶在url後邊展示在位址列,params傳參的引數不會展示到位址列。需要注意的是接收引數的時候是route而不是router。兩種方式一一對應,名字不能混用。
$router(傳值):為VueRouter例項,想要導航到不同URL,則使用$router.push方法
$route(獲取值):為當前router跳轉物件裡面可以獲取name、path、query、params等
返回上一個history也是使用$router.go方法