一、this.$router.push
1.1 使用方法
1.声明式
< router-link :to="…">:当使用router-link进行路由跳转时,实际上是调用了router.push()进行路由跳转
2.编程式 :this.$router.push(’路径‘)
1.2 使用语句
1.字符串
this.$router.push(‘index’)2.对象
this.$router.push({path:‘index’})
3.携带参数
3.1 path 跳转方式,只可以用query传参this.$router.push( {path:‘login’, query: { userName: ‘01testuser2’}})
3.2 name 跳转方式,可以用query和params传参
this.$router.push( {name:‘login’, query: { userName: ‘01testuser2’}})this.$router.push( {name:‘login’, params: { userName: ‘01testuser2’}})
3.3query传参与params传参区别:query传参相当于get请求,在浏览器的url地址中会显示参数;params相当于post请求,在浏览器的地址栏中不显示。
二、this.$router.replace
this.router.replace的使用与this.router.replace的使用与this.router.replace的使用与this.router.push相同,区别就是通过this.router.push()进行路由跳转,会在路由栈中添加一个记录,点击浏览器的返回时会跳转到上一个页面。而this.router.push()进行路由跳转,会在路由栈中添加一个记录,点击浏览器的返回时会跳转到上一个页面。而this.router.push()进行路由跳转,会在路由栈中添加一个记录,点击浏览器的返回时会跳转到上一个页面。而this.router.replace不会在路由栈中添加记录。