问题
I want to update query on url. But, $router.push does not updating url. disp
is different value for each call. Why?
handle: function(disp) {
let route = Object.assign({}, this.$route);
route.query.disp = disp;
this.$router.push(route);
},
versions.
"vue": "^2.5.17",
"vue-router": "^3.0.1",
route (console.log)
回答1:
You shouldn't try to push to the route object. Instead you should use one of these:
// literal string path
router.push('home')
// object
router.push({ path: 'home' })
// named route
router.push({ name: 'user', params: { userId: 123 }})
// with query, resulting in /register?plan=private
router.push({ path: 'register', query: { plan: 'private' }})
In your case:
this.$router.push({path: this.$route.path, query: {disp: disp}})
回答2:
I stopped copy of this.$route
object. That is works fine.
来源:https://stackoverflow.com/questions/52973554/vue-router-this-router-push-not-working-when-updating-query