首页
归档
笔记
树洞
搜索
友言

文章详情

Interesting People Record Interesting.

/ JavaScript / 文章详情

vue实现动态改变地址栏的参数值

Sonder
2021-06-30
424字
1分钟
浏览 (2.9k)

复制代码
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监听,将值动态的换到地址栏上去,这样刷新就是你点击的最新的啦

下一篇 / 文字溢出边缘羽化 CSS Mask 实现

🎯 相关文章

💡 推荐文章

🕵️‍♂️ 评论 (0)