其实就是想实现一个最简单的vue路由的功能,用的是vue-router2.0.0,我的代码是这样的:
视图层:
<div id="box">
<div>
<router-link to="/index">首页</router-link>
<router-link to="/news">新闻</router-link>
</div>
<router-view></router-view>
</div>
js:
const index={template:"<h3>我是主页</h3>"};
const news={template:'<h3>我是新闻页</h3>'};
const routers=[
{path:'/', redirect:'/index'},
{path:'/index', component:index},
{path:'/news', component:news}
]
const newRouter=new VueRouter({
routers:routers
})
const app=new Vue({
el:'#box',
router:newRouter
})
最后的效果:
new VueRouter里面
routers:routers
改为routes: routers