安装vue-router
cnpm install vue-router
配置
在src目录下新建router/index.js:代码如下:
/**
* Created by wy on 2017/3/7.
*/
import index from '../page/index/index.vue'
import search from '../page/search/search.vue'
import user from '../page/user/user.vue'
import details from '../page/details/details.vue'
//配置路由
export default [
{
path:"/",
component:index
},
{
path:"/search",
component:search
}
]
在main.js下配置
import Vue from 'vue'
import VueRouter from 'vue-router'
import App from './App.vue'
import axios from 'axios'
//引入路由配置文件
import routes from './router/index'
//使用VueRouter
Vue.use(VueRouter);
/ /使用axios
Vue.prototype.$http = axios
//使用配置文件
// 使用配置文件规则
const router = new VueRouter({
routes
})
new Vue({
router,
el: '#app',
render: h => h(App)
})
路由配置完毕!!!!