import Vue from 'vue';import App from './App.vue';//引入公共的scss 注意:创建项目的时候必须用scssimport './assets/css/basic.scss'; //请求数据import VueResource from 'vue-resource';Vue.use(VueResource);import VueRouter from 'vue-router';Vue.use(VueRouter);//1.创建组件import Home from './components/Home.vue';import News from './components/News.vue';import Content from './components/Content.vue';//2.配置路由 注意:名字const routes = [ { path: '/home', component: Home }, { path: '/news', component: News,name:'news' }, { path: '/content/:aid', component: Content }, /*动态路由*/ { path: '*', redirect: '/home' } /*默认跳转路由*/]//3.实例化VueRouter 注意:名字const router = new VueRouter({ mode: 'history', /*hash模式改为history*/ routes // (缩写)相当于 routes: routes})//4、挂载路由new Vue({ el: '#app', router, render: h => h(App)})//5放在 App.vue
我是首页组件