1:router-link

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

2:this.$router.push()

<template>
 <div id='test'>
 <button @click='goTo()'>点击跳转4</button>
 </div>
</template>
<script>
 export default{
 name:'test',
 methods:{
	 goTo(){
	 	//直接跳转
	 	this.$router.push('/testDemo');
	  
	 	//带参数跳转
	 	this.$router.push({path:'/testDemo',query:{setid:123456}});
	 	this.$router.push({name:'testDemo',params:{setid:111222}});
	 }
 }
 }
</script>

在地址栏中可以看到,params传参数时,地址栏中看不到参数的内容,有点像ajax中的post传参,query传参数时,地址栏中可以看到传过来的参数信息,有点像ajax的个体传参

如果单独传setId一个参数的时候,地址栏中的地址如下图:在这里插入图片描述
第一种方式:path - query 传参在这里插入图片描述
第二种方式:name - params传参数
但是一般情况下,传参数是传递一个对象,当传递的是一个对象的时候,地址栏中的地址如下图:在这里插入图片描述
第一种方式:path - query 传参在这里插入图片描述
第二种方式:name - params传参数

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

接收方怎么接收参数??
this.$route.query.serid和this.$route.params.setid
4.其他方法
this.router.go(1);this.router.go(1); this.router.go(1);this.router.go(-1);

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐