1: router-link jump
<!-- 直接跳转 -->
<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>
What is the difference between params and query parameters? ? As you can see in the address bar, when params is passing parameters, the content of the parameters cannot be seen in the address bar, which is a bit like post passing parameters in ajax. When query passing parameters, the passed parameter information can be seen in the address bar. Individual parameter transfer like ajax
If a parameter of setId is passed alone, the address in the address bar is as shown in the figure below:
Recommend the second way
<button @click="goHome">[跳转到主页]</button>
export default {
name: "App",
methods: {
// 跳转页面方法
goHome() {
this.$router.push("/");
},
}