如何解决vue-router的子页面不渲染?

其实就是想实现一个最简单的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
    })

最后的效果:
图片描述

阅读 4.5k
1 个回答

new VueRouter里面
routers:routers 改为 routes: routers

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题