vue点击刷新 路由怎么回到当前根目录

加这个是刷新回到首页

mounted:function(){
    this.$router.push('/home');
}

怎么改成刷新回到当前路由根目录

clipboard.png

clipboard.png

阅读 7.9k
2 个回答
mounted:function(){
    var path = this.$route.path.match(/^\/[^\/]*/)[0]
    this.$router.push(path);
}

可以使用router提供的matched获取path

mounted:function(){
    var path = this.$route.matched[1].path;
    this.$router.push(path);
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题