Vue支持的跳转:
通过注入路由器,我们可以在任何组件内通过 this.$router 访问路由器,也可以通过 this.$route 访问当前路由(以下两图分别是this.$router、this.$route对象)。


跳转到相应的页面我们使用this.$router.push
// 不带参数 this.$router.push('index/') // 带参数 this.$router.push({name:'login', params:{userId: 'user',password:'123'}}) this.$router.push({path:'folder', query:{folderId:'1'}})
需要注意的是由于动态路由也是传递params的,所以在 this.$router.push() 方法中path不能和params一起使用,否则params将无效。需要用name来指定页面。query和params区别是:query 相当于 get 请求,页面跳转的时候可以在地址栏看到请求参数,params 相当于 post 请求,参数不在地址栏中显示。
to apple
url
folder
window.open跳转:
vue跳转只支持单页面跳转,当需求跳转时打开新页面需要使用window.open,使用方法具体使用方法可在菜鸟教程中查看,这里给出在新Tab页中打开和新window中打开的例子
//在新Tab中打开 openUrlInNewTab(url) { this.blurButton() if (!url.startsWith('/')) { url = '/' + url } window.open(url) }
// 在新window中打开 openUrlInNewWindow( url, features = ['resizable', 'scrollbars', 'width=832', 'height=1200']) { if (!url.startsWith('/')) { url = '/' + url } window.open(url, '_blank', features.join()) },
发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/226697.html原文链接:https://javaforall.net
