使用动态名称作为参数Vuejs

时间:2020-03-27 08:15:46

标签: vue.js vuejs2

我有多个参数,当我执行一个get请求时,我只想拥有一个将参数名称作为其值的函数。

问题是,参数是我定义的,而不是值。

this.debounce("search_fullname", 5);

debounce(searchField, value) {
  this.$router.push({
    query: {
     ...this.$route.query,
     searchField: value 
    }
  })
 }

在网址中,我得到/?searchField=5而不是/?search_fullname=5

1 个答案:

答案 0 :(得分:1)

this.debounce("search_fullname", 5);

debounce(searchField, value) {
  this.$router.push({
    query: {
      ...this.$route.query,
      [searchField]: value <--- Dynamic key in js object
    }
  })
}

您将在网址中获得/?search_fullname=5而不是/?searchField=5

相关问题