# Vue2-SPA > A Vue.js project width axios/vue-router/webpack ## Build Setup ``` bash # install dependencies npm install # serve with hot reload at localhost:8080 npm run dev # build for production with minification npm run build ``` ## Lifecycle ![image](https://github.com/allan2coder/Vue2-SPA2/blob/master/screenShot/lifecycle.png) ``` bash ``` ## Router HTML ``` bash import Vue from 'vue' import VueRouter from 'vue-router' or

Go to Foo Go to Bar

``` JavaScript ``` bash // 0. 如果使用模块化机制编程,導入Vue和VueRouter,要调用 vue.use(vuerouter) // 1. 定义(路由)组件。 // 可以从其他文件 import 进来 const Foo = { template: '
foo
' } const Bar = { template: '
bar
' } // 2. 定义路由 // 每个路由应该映射一个组件。 其中"component" 可以是 // 通过 Vue.extend() 创建的组件构造器, // 或者,只是一个组件配置对象。 // 我们晚点再讨论嵌套路由。 const routes = [ { path: '/foo', component: Foo }, { path: '/bar', component: Bar } ] // 3. 创建 router 实例,然后传 `routes` 配置 // 你还可以传别的配置参数, 不过先这么简单着吧。 const router = new VueRouter({ routes // (缩写)相当于 routes: routes }) // 4. 创建和挂载根实例。 // 记得要通过 router 配置参数注入路由, // 从而让整个应用都有路由功能 const app = new Vue({ router }).$mount('#app') // 现在,应用已经启动了! ``` # Reference Articles * [Vue-Router](http://router.vuejs.org/zh-cn/essentials/getting-started.html) * [ECMAScript 6入门](http://es6.ruanyifeng.com/) * [Webpack 入门指迷](https://segmentfault.com/a/1190000002551952) * [webpack使用优化](https://github.com/lcxfs1991/blog/issues/2) * [vue guide](http://vuejs-templates.github.io/webpack/) * [docs for vue-loader](http://vuejs.github.io/vue-loader)