vue跳转页面的方法
1.router-link跳转
<!-- 直接跳转 --> <router-link to='/index'> <button>点击跳转</button> </router-link> <!-- 带参数跳转 --> <router-link :to="{path:'index',query:{id:1}}"> <button>点击跳转</button> </router-link> <router-link :to="{name:'index',params:{id:1}}"> <button>点击跳转3</button> </router-link>
2.this.$router.push()
//直接跳转 this.$router.push('/index'); //带参数跳转 this.$router.push({path:'/index',query:{id:1}}); this.$router.push({name:'index',params:{id:1}});
params和query传参的不同:
- params传参数时,地址栏中看不到参数的内容,有点像ajax中的post传参
- query传参数时,地址栏中可以看到传过来的参数信息,有点像ajax的个体传参
3. a标签可以跳转外部链接,不能路由跳转
发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/231538.html原文链接:https://javaforall.net
