vue-cli(二级路由)

83 阅读1分钟

router文件->index.js:  children:[{ }]:

{
    path: '/test',
    component: test,
    children: [
      {
        path: '/a',
        componcent: Home
      },
      {
        path: '/b',
        componcent: test
      }
    ]
  }
复制代码

注:如果报错,重新使用npm脚本int,然后再运行

然后再views文件中的test文件的test.vue中引用router-link和router-view:

<template>
  <div id="app">
    <div id="nav">
        <router-link to="/a">a</router-link>
        <router-link to="/b">b</router-link>
    </div>
    <router-view/>
  </div>
</template>
<script type="text/ecmascript-6">
export default {

}
</script>
<style lang="scss" scoped></style>

复制代码

注:二级路由需要div嵌套在里面

效果:

image.png

image.png

image.png