vue.js怎麼進行頁面跳轉?

2020-11-25 18:01:28

  • 該方法適用於所有品牌的電腦。

vue跳轉頁面的方法

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>
 <p id='test'>
 <button @click='goTo()'>點選跳轉4</button>
 </p>
</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和query傳引數有什麼不一樣??在位址列中可以看到,params傳引數時,位址列中看不到引數的內容,有點像ajax中的post傳參,query傳引數時,位址列中可以看到傳過來的引數資訊,有點像ajax的個體傳參

如果單獨傳setId一個引數的時候,位址列中的地址如下圖:

1.png

第一種方式:path - query 傳參

2.png

第二種方式:name - params傳引數

但是一般情況下,傳引數是傳遞一個物件,當傳遞的是一個物件的時候,位址列中的地址如下圖:

3.png

第一種方式:path - query 傳參

4.png

第二種方式:name - params傳引數

<p id="app">
			<p v-show="isShow">微風輕輕的吹來,帶來了一絲絲涼意</p>
			<p>
				<button type="button" v-on:click="show(1)">顯示</button>
				<button type="button" v-on:click="show(0)">隱藏</button>
			</p>
		</p>
		
		var vm = new Vue({
			el: '#app',
			data: {
				isShow:true
			},
			methods:{
				show:function(type){
					if(type){
						this.isShow = true;
					}else{
						this.isShow = false;
					}
				}
			}
		})

更多程式設計相關知識,請存取:!!

以上就是vue.js怎麼進行頁面跳轉?的詳細內容,更多請關注TW511.COM其它相關文章!