# vue2-spa-tutorial
**Repository Path**: PorcoMar/vue2-spa-tutorial
## Basic Information
- **Project Name**: vue2-spa-tutorial
- **Description**: No description available
- **Primary Language**: Unknown
- **License**: Not specified
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 0
- **Created**: 2017-09-05
- **Last Updated**: 2020-12-19
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# Vue2-SPA
> A Vue.js project with axios/vue-router/webpack
## How to use
You should clone the repo and install the dependencies, and then npm start.That is all.
```bash
$ npm start
```
You should see a new browser tap opening and a page of 'index.html' in http://localhost:8080.
## How to build the static files
``` bash
npm run build
```
## Router
HTML
``` bash
import Vue from 'vue'
import VueRouter from 'vue-router'
Go to Foo
Go to Bar
or
```
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')
// 现在,应用已经启动了!
```
### 生产环境要注意的地方:
> 1、生产环境下若项目不是放在服务器的根目录下会访问不到静态资源,此时,你只需要修改下config文件夹内index.js的build中的assetsPublicPath即可
```
before:
assetsPublicPath: '/',
```
```
after:
assetsPublicPath: '/wx/otherPath/static',
```
> 2、在写静态资源的时候最好使用相对路径,如:
```
error:
background: url(../assets/img/icon.png);
```
```
right:
background: url(./../assets/img/icon.png);
```