How to set URL query params in Vue with Vue-Router

前端 未结 9 810
梦如初夏
梦如初夏 2020-12-23 20:24

I am trying to set query params with Vue-router when changing input fields, I don\'t want to navigate to some other page but just want to modify url query params on the same

9条回答
  •  心在旅途
    2020-12-23 20:37

    For adding multiple query params, this is what worked for me (from here https://forum.vuejs.org/t/vue-router-programmatically-append-to-querystring/3655/5).

    an answer above was close … though with Object.assign it will mutate this.$route.query which is not what you want to do … make sure the first argument is {} when doing Object.assign

    this.$router.push({ query: Object.assign({}, this.$route.query, { newKey: 'newValue' }) });
    

提交回复
热议问题