«

vue路由

emer 发布于 2017-8-14 14:53   2383 次阅读     


模板news页:


<div>
      <router-link to="/home" tag="li" >主页</router-link>
      <router-link to="/list">列表</router-link>
    </div>
    <div class="container">
    <router-view></router-view>


router config:


import Home from "./components/home.vue"
import List from "./components/list.vue"
export default{
    routes:[{
                path:"/home",
                component:Home
            },{
                path:"/list",
                component:List
            },
            {
                path:"*",
                redirect:"/list"
            }
    ]
}

最后在main.js里面配置:

import Vue from 'vue'
import App from './App.vue'
import routes from "../router.config.js"
import VueRouter from 'vue-router'
import ElementUi from "element-ui"
import 'element-ui/lib/theme-default/index.css'
Vue.use(VueRouter);
Vue.use(ElementUi)
const router=new VueRouter(routes);
new Vue({
  router,
  el: '#app',
  render: h => h(App)
})