34-vue中的编程式路由导航

理解

  编程式路由导航:用js代码来实现页面跳转 (例如点击按钮,添加事件监听使得页面来跳转)

window.location.href = url
window.location = url  //简洁写法

组件对象this的两个属性

  组件对象有两个属性:$route $router. 。
   $route代表当前组件,存储着一些数据;
   $router代表路由器,有一些功能性的方法

$router属性中的三个功能性方法

  1. this.$router.push(path): 相当于点击路由链接(可以返回到当前路由界面)
  2. this.$router.replace(path): 用新路由替换当前路由(不可以返回到当前路由界面)
  3. this.$router.back(): 请求(返回)上一个记录路由

$router属性的用法示例

在这里插入图片描述

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/A_Bow/article/details/114239387