Vuejs2 如何从vue路由器中删除查询?
所有删除查询字符串的尝试都失败Vuejs2 如何从vue路由器中删除查询?,vuejs2,vue-router,Vuejs2,Vue Router,所有删除查询字符串的尝试都失败 // Initial state this.$router.replace({ name: 'routeName', query: { param: 123 } }); // Errors this.$rout
// Initial state
this.$router.replace({
name: 'routeName',
query: {
param: 123
}
});
// Errors
this.$router.replace({ query: {}});
this.$router.replace({ query: undefined });
this.$router.replace({ query: null });
如何在没有任何错误的情况下删除查询
Vue router v3.1.5出于某种原因
router.replace()
&router.push()
需要一个非空对象作为查询。所以剩下的工作就是从值中清除初始查询对象,如:
let query = {
param: [1, 2, 3]
};
// Initial state
this.$router.push({
name: 'yourRouteName',
query: query
});
// clean your initial query object
query.param = [];
// Now replace it
this.$router.replace({
query: query
});
请尝试以下代码:
let query = Object.assign({}, this.$route.query);
delete query.param;
this.$router.replace({ query });