vue跳转页面的几种常用方法代码示例
更新时间:2023年10月10日 10:28:18 作者:硕霸天下
这篇文章主要给大家介绍了关于vue跳转页面的几种常用方法,vue跳转页面有好几种不同方法,文中通过代码将实现的方法介绍的非常详细,对大家学习或者使用vue具有一定的参考借鉴价值,需要的朋友可以参考下
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.baidu.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="./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>总结
到此这篇关于vue跳转页面的几种常用方法的文章就介绍到这了,更多相关vue跳转页面方法内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!
相关文章
详细聊聊前端如何实现token无感刷新(refresh_token)
实现token无感刷新对于前端来说是一项非常常用的技术,其本质是为了优化用户体验,下面这篇文章主要给大家介绍了关于前端如何实现token无感刷新(refresh_token)的相关资料,需要的朋友可以参考下2022-11-11
Vue如何使用ElementUI对表单元素进行自定义校验及踩坑
有一些验证不是通过input select这样的受控组件来触发验证条件的 ,可以通过自定义验证的方法来触发,下面这篇文章主要给大家介绍了关于Vue如何使用ElementUI对表单元素进行自定义校验及踩坑的相关资料,需要的朋友可以参考下2023-02-02
Vue中的无限加载vue-infinite-loading的方法
本篇文章主要介绍了Vue中的无限加载vue-infinite-loading的方法,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧2018-04-04
Vue3中导入和使用图标库Font Awesome的实现步骤
Font Awesome 是互联网的图标库和工具包,被数百万设计师、开发人员和内容创建者使用,Font Awesome的图标非常丰富,基本涵盖你所需要的所有,本文给大家介绍了Vue3中导入和使用图标库Font Awesome的具体步骤,需要的朋友可以参考下2025-01-01


最新评论