在Vue项目中使用Vue-router的另一种形式

1、在src目录下创建一个router文件夹,在里面创建router.js

npm install vue-router

 

 2、router.js

 1 import Vue from 'vue'
 2 import Router from 'vue-router'
 3 
 4 import Home from '../page/home/Home.vue'
 5 
 6 Vue.use(Router)
 7 
 8 const routes = [
 9   {
10     path: '/',
11     component: Home,
12   },
13 ]
14 
15 export default new Router({
16   routes,
17   strict: process.env.NODE_ENV !== 'production',
18 })
View Code

3、main.js

import Vue from 'vue'

import App from './App.vue'
import router from './router/router'
import './element/index'
import 'element-ui/lib/theme-chalk/index.css'

Vue.config.productionTip = false

new Vue({
  router,
  render: (h) => h(App),
}).$mount('#app')
View Code

 

posted @ 2020-05-29 15:57  haha-uu  阅读(207)  评论(0编辑  收藏  举报