Nuxt / Vue查询对象在更改后返回旧查询

时间:2018-02-13 15:28:06

标签: javascript vuejs2 nuxt.js

鉴于这是一个nuxt链接:

<nuxt-link :to="generateCategoryLink($store.state.locale, category.id)" exact :class="{active: isCategoryActive(category.id)}">

// Calls this method to get the link
generateCategoryLink(locale, categoryID) {
  let query = this.$nuxt.$route.query;

  if (this.isCategoryActive(categoryID)) {
    query.categories = this.getQueriedCategories(categoryID);
  } else {
    query.categories = this.getQueriedCategories() + (this.getQueriedCategories() ? "," : "") + categoryID;
  }

  return {path: '/' + locale + '/projects/1', query};
}

如果我使用此代码,该方法始终返回旧params的链接。将此更改为:

return {path: '/' + locale + '/projects/1', query: { categories: query.categories}};

有效,但因为我想要包含所有其他旧的参数(仅修改query.categories),这不是一个选项。

1 个答案:

答案 0 :(得分:0)

这应该可以解决问题:

return {path: '/' + locale + '/projects/1', query: { ...query, categories: query.categories}};