首页 > 技术文章 > vue实现动态改变地址栏的参数值

chenzhengyang 2019-10-12 10:41 原文

  watch: {
    id (val) {
      let query = this.$router.history.current.query;
      let path = this.$router.history.current.path;
      //对象的拷贝
      let newQuery = JSON.parse(JSON.stringify(query));
      // 地址栏的参数值赋值
      newQuery.id = val;
      this.$router.push({ path, query: newQuery });
    }
  },
我的需求是,点击切换上下篇文章,我就在地址栏添加了参数,但是切换刷新后,还是原来的;所以就通过在点击的时候,将值赋值到data里面,然后通过watch监听,将值动态的换到地址栏上去,这样刷新就是你点击的最新的啦

推荐阅读