我试图在更改输入字段时将查询参数设置为Vue-router,我不想导航到其他页面,但只想修改同一页面上的url查询参数,我是这样做的:
this.$router.replace({ query: { q1: "q1" } })
但这也会刷新页面,并将y位置设置为0,即滚动到页面顶部.这是设置URL查询参数的正确方法还是有更好的方法.
编辑:
这是我的路由代码:
export default new Router({
mode: 'history',
scrollBehavior: (to, from, savedPosition) => {
if (to.hash) {
return {selector: to.hash}
} else {
return {x: 0, y: 0}
}
},
routes: [
.......
{ path: '/user/:id', component: UserView },
]
})