Vue.js Vue路由器-更新或清除查询
我正在编写一个ui过滤器,它应该将所有活动过滤器作为查询参数输出Vue.js Vue路由器-更新或清除查询,vue.js,vue-router,Vue.js,Vue Router,我正在编写一个ui过滤器,它应该将所有活动过滤器作为查询参数输出 const query = this.$route.query if (!query[type]) { return this.$router.push({ query: { ...query, [type]: value } }) // works fine! } if (Array.isArray(query[type])) { // some changes } this.$router.replace(
const query = this.$route.query
if (!query[type]) {
return this.$router.push({ query: { ...query, [type]: value } }) // works fine!
}
if (Array.isArray(query[type])) {
// some changes
}
this.$router.replace({ query: { ...query } })
但它不起作用!如果参数之前是一个字符串,然后变为一个数组(例如:
query:'1'
到query:[1,2]
,那么路由器将忽略更新。或者如果所有筛选器都已清除,我需要清除地址栏。您可以通过设置query={}来清除地址栏;
我发现问题发生在旧版本的vue路由器上,如2.1.2。我无法在最新版本上重现。是否可以升级您的vue路由器版本或尝试上提到的解决方法。