鍍金池/ 問答/HTML/ vue 改變 query 參數(shù)的一個奇怪問題

vue 改變 query 參數(shù)的一個奇怪問題

當前路由例如 /search,我想跳轉(zhuǎn)到 /search?p=1,首頁想到是先讀取this.$route.query,然后修改p實現(xiàn)跳轉(zhuǎn),
但我項目里下面push方法并沒有跳轉(zhuǎn)到我想到的url

let newQuery = this.$route.query //讀取query參數(shù)
newQuery.p   = val //修改頁碼

let routeParam={
    query: newQuery
}

this.$router.push(routeParam)

以上問題我想可能是我對vue-router不了解,所以不知道哪里不對,但奇怪的地方是下面代碼卻能成功跳轉(zhuǎn)到我想要的url,我打印出來 routeParam,看有任何區(qū)別

let newQuery = {}
newQuery.p   = val
let routeParam={
    query: newQuery
}
this.$router.push(routeParam)

事實上我想改變的不只是 p參數(shù),所以每次都讀this.$route.query,然后修改
但出現(xiàn)以上我不理解問題,我是不是漏掉什么細節(jié)?

回答
編輯回答
默念

看代碼的話應該是 值與址的問題.

            let newQuery = JSON.parse(JSON.stringify(this.$route.query)); //讀取query參數(shù)
            newQuery.p = val
            let routeParam={
                query: newQuery
            }
            this.$router.push(routeParam)
2017年11月20日 06:54
編輯回答
柚稚

看到一個相似問題vue路由請求參數(shù)被改變

this.$route.query 是傳址調(diào)用?

2017年12月13日 16:23
編輯回答
老梗
this.$router.push({path:'/index/detail',query:{id:xx,num:xxx}});
query是攜帶參數(shù)
你path沒有 怎么會跳轉(zhuǎn)
你要跳轉(zhuǎn)的路由在哪里?
2018年5月13日 01:18