在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 })
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')
记录自己的采坑之路,需要时方便查找