vue路由傳參

對應(yīng)的路由配置模塊

,{
      path: '/editCardetail',
      name: 'editCardetail',
      component: EditCardetail
    }

1、使用$router.push 拼接參數(shù)傳參

 this.$router.push('/editCardetail?editType=add')

其中editType=add即為傳遞的參數(shù)

2、 使用name來確定匹配的路由,通過params來傳遞參數(shù)

this.$router.push({
                      name: 'editCardetail',
                      params: {
                        editType: add
                      }
                    })

3、使用path來匹配路由,然后通過query來傳遞參數(shù)

this.$router.push({
                     path: '/editCardetail',
                      query: {
                        editType: add
                      }
                    })

注意:path不能與params一起使用,需要通過path來匹配路由的時候,使用query來傳參。
query要用path來引入,params要用name來引入,接收參數(shù)都是類似的,分別是this.route.query.name和this.route.query.name和this.route.query.name和this.route.params.name。
query更加類似于我們ajax中g(shù)et傳參,params則類似于post,前者在瀏覽器地址欄中顯示參數(shù),后者則不顯示。

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容