• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

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

武飞扬头像
硕霸天下
帮助1

目录

vue跳转不同页面的方法

1.router-link跳转

2.this.$router.push()

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

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

this.$router.push("/")

this.$router.go(1)

代码示例:

vue跳转不同页面的方法

1.router-link跳转

<!-- 直接跳转 -->
<router-link to='/testC'>
 <button>点击跳转2</button>
</router-link>
 
<!-- 带参数跳转 -->
<router-link :to="{path:'testC',query:{setid:123456}}">
 <button>点击跳转1</button>
</router-link>
 
<router-link :to="{name:'testC',params:{setid:1111222}}">
 <button>点击跳转3</button>
</router-link>

2.this.$router.push()

<template>
 <div id='app'>
 <button @click='goTo()'>点击跳转4</button>
 </div>
</template>
<script>
 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}});
 }
 }
 })
</script>

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

<a href="https://www.百度.com"><button>点击跳转5</button></a>

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

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

Vue:router-link

 <router-link to="/">[跳转到主页]</router-link>
 <router-link to="/login">[登录]</router-link>
 <router-link to="/logout">[登出]</router-link>
this.$router.push("/");

this.$router.push("/")

<button @click="goHome">[跳转到主页]</button>
export default {
 name: "App",
 methods: {
 // 跳转页面方法
 goHome() {
 this.$router.push("/");
 },
}

this.$router.go(1)

 <button @click="upPage">[上一页]</button>
 <button @click="downPage">[下一页]</button>
 upPage() {
 // 后退一步记录,等同于 history.back()
 this.$router.go(-1);
 },
 downPage() {
 // 在浏览器记录中前进一步,等同于 history.forward()
 this.$router.go(1);
 }
 

代码示例:

<template>
 <div id="app">
 <img src="https://blog.csdn.net/m0_70031574/article/details/assets/logo.png">
 <router-view/>
 <router-link to="/">[跳转到主页]</router-link>
 <router-link to="/login">[登录]</router-link>
 <router-link to="/logout">[登出]</router-link>
 
 <!-- javascript跳转页面 -->
 <button @click="goHome">[跳转到主页]</button>
 
 <!-- 回到上一页 -->
 <button @click="upPage">[上一页]</button>
 <button @click="downPage">[下一页]</button>
 
 <!-- 回到下一页 -->
 
 </div>
</template>
 
<script>
 export default {
 name: "App",
 methods: {
 // 跳转页面方法
 goHome() {
 this.$router.push("/");
 },
 upPage() {
 // 后退一步记录,等同于 history.back()
 this.$router.go(-1);
 },
 downPage() {
 // 在浏览器记录中前进一步,等同于 history.forward()
 this.$router.go(1);
 }
 }
 };
</script>

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanhhkbkbf
系列文章
更多 icon
同类精品
更多 icon
继续加载