1、安裝插件(可以選擇在初始化項目的時候安裝)
cnpm install vue-router --save-dev
2、將插件全局引入到項目中(main.js)
import VueRouter from 'vue-router'
3、將插件注入到vue中(main.js)
Vue.use(VueRouter) //全局使用該組件
4、創建組件(需要跳轉的頁面),舉例如下:
5、配置路由(router.js),先引入組件,再寫配置,最后導出(export...)
6、生成router實例(main.js)並傳routes(路由)配置
先將 router.js 引入進來
import routers from './router/router'
const router = new VueRouter({ mode:'history', //模式 routes:routers //routes是一組路由
})
7、生成 vue 實例 (main.js),並將路由注入到整個項目
new Vue({ el: '#app', //掛載根實例 router,//注入到根目錄中 components: { App }, template: '<App/>' })
8、在項目主組件(APP.vue)中寫路由跳轉,例:
或者:
this.$router.push({ path: '/orderCommit', query: { date: this.dateValue } })
二、二級路由
1、在一級路由的基礎上,路由配置中加上children
2、在一級組件中加上顯示
OK~
this.
$router.
push({
path:
'/orderCommit',
query: {
date:
this.
dateValue,
timeSlot:
this.
timeState,
timeSlotLast:
this.
timeSlotLast,
tableInfo:
myTableInfo,
tableId:
this.
tableIdStr,
isCourt:
this.
isCourt,
peopleNum:
peopleNum
}
})