一、在template中的常見寫法: <router-link to="/recommend"> <button class="button">點擊跳轉</button> </router-link> 二、在js中設置跳轉(在方法中跳轉界面並傳參,兩種方式:params 與 query): 有時候我們需要的是點擊按鈕跳出彈窗,選擇判斷后進行跳轉,我們常用.$router.push 跳轉 傳參: <button @click = "func()">跳轉</button> //js <script> export default{ methods:{ func (){ this.$router.push({name: '/order/page1',params:{ id:'1'}}); } } } </script> 另有: this.$router.push({path: ''/order/index''}); this.$router.push({path: '/order/page1',query:{ id:'2'}}); this.$router.push({name: '/order/page2',params:{ id:'6'}}); // path:'路由里配置的index.vue的路徑' // params:{id:'1',name:'eva'} /query:{id:'5'} 需要傳遞的參數和值 路由傳參params 和query兩種方式的區別: 1、用法上的 剛才已經說了,query要用path來引入,params要用name來引入,接收參數都是類似的,分別是this.route.query.name和this.route.params.name。 注意接收參數的時候,已經是route而不是router了哦!! 2、展示上的 query更加類似於我們ajax中get傳參,params則類似於post,說的再簡單一點,前者在瀏覽器地址欄中顯示參數,后者則不顯示。 三、路由參數的取值: {{this.$route.params.參數名}} 注意:接收參數的時候已經是route而不是router了。
