一. 配置路由的 index.js 文件
在router文件夾中新建 index.js 文件
導入vue,vue-router 以及路由模塊
使用路由模塊
導出VueRouter
配置路由

此代碼為一個路由數(shù)組(注意是routes);
第一項包含redirect參數(shù),表示默認路徑,其中的query表示路由傳遞的參數(shù),為object類型;
二. 使用路由
- 在router-link的標簽中綁定
- :to="{path:'/sales',query:{type:'All'}}"
path表示路由路徑,query表示路由傳遞的參數(shù)obj - tag='div'
router-link的標簽頁面中默認渲染為 a標簽,通過這個參數(shù)可改變,此代碼表示渲染為 div 標簽

三. 目標模塊中獲取傳遞參數(shù)
在路由至的目標模塊中,想要獲取通過路由傳遞的參數(shù)
可通過 this.$route.query.type 獲取,如下圖所示
