小工具知识网

当前位置: 首页 > 行业知识 > vue跳转页面的几种常用方法

行业知识

vue跳转页面的几种常用方法

2026-11-16 02:24:14 来源:互联网转载

目录

vue跳转不同页面的方法

1.router-link跳转

2.this.$router.push()

3.a标签可以跳转外部链接,不能路由跳转

vue三种不同方式实现跳转页面

Vue:router-link

this.$router.push("/")

this.$router.go(1)

代码示例:

vue跳转不同页面的方法

1.router-link跳转

 点击跳转2

 

 点击跳转1

 

 点击跳转3

2.this.$router.push()

 

 点击跳转4

 

 new Vue({

 el:'#app',

 methods:{

 goTo(){

 //直接跳转

 this.$router.push('/testDemo');

 //带参数跳转

 this.$router.push({path:'/testC',query:{setid:123456}});

 this.$router.push({name:'testC',params:{setid:111222}});

 }

 }

 })

3.a标签可以跳转外部链接,不能路由跳转

点击跳转5

接收:this.$route.query.serid 和 this.$route.params.setid

vue三种不同方式实现跳转页面

Vue:router-link

 [跳转到主页]

 [登录]

 [登出]

this.$router.push("/");

this.$router.push("/")

[跳转到主页]

export default {

 name: "App",

 methods: {

 // 跳转页面方法

 goHome() {

 this.$router.push("/");

 },

}

this.$router.go(1)

 [上一页]

 [下一页]

 upPage() {

 // 后退一步记录,等同于 history.back()

 this.$router.go(-1);

 },

 downPage() {

 // 在浏览器记录中前进一步,等同于 history.forward()

 this.$router.go(1);

 }

 

代码示例:

 

 

 

 [跳转到主页]

 [登录]

 [登出]

 

 

 [跳转到主页]

 

 

 [上一页]

 [下一页]

 

 

 

 

 

 export default {

 name: "App",

 methods: {

 // 跳转页面方法

 goHome() {

 this.$router.push("/");

 },

 upPage() {

 // 后退一步记录,等同于 history.back()

 this.$router.go(-1);

 },

 downPage() {

 // 在浏览器记录中前进一步,等同于 history.forward()

 this.$router.go(1);

 }

 }

 };

上一篇:服务器问题怎么解决好呢?

下一篇:笔记本上使用usb蓝牙适配器