首页 > 解决方案 > 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({ query: { ...query } })

但它不起作用!如果之前的参数是一个字符串,然后变异成一个数组(例如:query: '1'toquery: [1, 2]那么路由器会忽略更新。或者如果所有过滤器都已清除,我需要清除地址栏。

标签: vue.jsvue-router

解决方案


推荐阅读