通過方法跳轉(zhuǎn)頁面
1):不傳參數(shù)
<button @click = "func()">跳轉(zhuǎn)</button>
?//js
<script>
?????export default{
?????????????methods:{
?????????????????????func (){
? ? ? ? ? ? ? ? ? ? ? ? ? ??this.$router.push({ path: '/version/version' });
? ? ? ? ? ? ? ? ? ? ? ?}
? ? ? ? ? ? ? ? }
?????????}
</script>?
?this.$router.push();路由跳轉(zhuǎn)? ?里面?zhèn)饕粋€對象? 建是? path? 值是要跳轉(zhuǎn)的路由? 對應(yīng) router/index.js文件中的每個頁面配置的 path;
2):傳參
this.$router.push({ name: 'collectionRecord',? ?params: { 鍵1:值1,鍵2:值2 }});
this.$router.push({ path: 'collectionRecord',? ?query: { 鍵1:值1,鍵2:值2 }});
? ? ==>> 路由傳參params? 和 query兩種方式;
? ? ==>> params要用name來引入,query要用path來引入;
? ? ==>>?接收參數(shù)都是類似的,分別是this.$route.params.鍵 和 this.$route.query.鍵曾棕。
? ? ==>> params類似于ajax中post,query更類似于get傳參,前者在瀏覽器地址欄中不顯示顯示參數(shù)宛蚓,后者則顯示
注意:接收參數(shù)的時候域仇,已經(jīng)是$route 而 不是$router了
浪客行1213的簡書
XHH