HTML+JS、VUE页面跳转的几种方式总结

一、HTML+JS实现跳转:

特别提醒:有些跳转方式是只能跳转一级页面,有些可以跳转多级页面,在使用时要注意选择跳转方式!

1、javascript中实现跳转:

// 直接跳转
window.location.href='index.html';
// 定时跳转
setTimeout("javascript:location.href='index.html'", 5000);

2、在html标签内实现跳转:
eg:onclick='window.location.href='../index.html'; οnclick="window.location.reload('../index.html');

<button id="load" οnclick="window.location.reload('../index.html')">跳转</button>  

3、html中的 a标签直接跳转:

<a href="http://baidu.com">百度一下</a>

4、html中使用meta中跳转,通过meta可以设置跳转时间和页面:
eg:<meta http-equiv="refresh" content="5";url="index.html">

<head>
<!--只是刷新不跳转到其他页面 -->
<meta http-equiv="refresh" content="5">
<!--定时转到其他页面 -->
<meta http-equiv="refresh" content="5";url="index.html"> 
</head>

5、html中跳转上一页的方式:
eg:window.history.go(-1);或者 window.history.back(-1);

<a href="#" onClick="javascript :history.back(1);">返回上一页</a>
<a href="#" onClick="javascript :history.go(-1);">返回上一页</a>

6、javascript中写跳转上一页:

<div id="btn">按钮</div>

<script type="text/javascript">
    var wrong = document.getElementById('btn');
      wrong.onclick = function() { 
	  window.history.go(-1);//返回上一页
	  window.history.back(-1);//返回上一页
   }
</script>
二、VUE实现跳转:

1、通过 @click='方法名' 跳转:

<template>
	<text @click="goHome"><u-icon name="arrow-left"></u-icon></text>
</template>
<script>
	methods: {
	// 方式一:点击返回首页
	goHome(){
		this.$router.replace('../home/home');
	},
	
	// 方式二:点击返回首页
	goHome() {
		uni.switchTab({
			url: '../home/home'
		})
	},
	
	// 方式三:点击返回首页
	goHome() {
		// 直接跳转
		this.$router.push('../home/home');
		
		// 带参数跳转
		this.$router.push({path:'../home/home',query:{setid:123456}});
	},
	}
</script>

2、通过 @tap='方法名' 跳转:

<template>
	<text @tap="goHome"><u-icon name="arrow-left"></u-icon></text>
</template>
<script>
	methods: {
	// 方式一:点击返回首页
	  goHome(){
			  uni.navigateTo({
			  	url:'../home/home'
			  })
		  },
	}
</script>

3、router-link跳转:

直接跳转:
<router-link to='./home'>
	 <button>点击跳转1</button>
<router-link to='/testDemo'>

带参数跳转:
<router-link :to="{path:'./home',query:{setid:123456}}">
	 <button>点击跳转2</button>
</router-link>

希望有帮助~大家还知道哪些跳转方式可以下方评论哦!

  • 5
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 6
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值