vue-router2.0二級路由的簡單使用
阿新 • • 發佈:2017-07-05
自己 我們 exp -m pat export username aaa group
1、app.vue中
<template> <div id="app"> <router-view></router-view> </div> </template>
2、router中index.js(路由的路徑配置)
import Vue from ‘vue‘ import Router from ‘vue-router‘ import Hello from ‘@/components/Hello‘ import Login from ‘@/components/Login‘ import index from‘@/components/index‘ import Header from ‘@/components/Header/Header‘ import Product from ‘@/components/Product/Product‘ Vue.use(Router) export default new Router({ routes: [ { path: ‘/‘, name: ‘Login‘, component: Login }, { path: ‘/index‘, name: ‘index‘, component: index, children: [//這裏就是二級路由的配置 { path: ‘/hello‘, name: ‘Hello‘, component: Hello }, { path: ‘/header‘, name: ‘Header‘, component: Header }, { path: ‘/product‘, name: ‘Product‘, component: Product } ] } ] })
3、下面是我們的index.vue中的代碼
<template> <div class="aaa"> <div class="list-group"> <router-link to="/hello">Go to hello</router-link> <router-link to="/header">Go to header</router-link> <router-link to="/product">Go to product</router-link> <input type="text" v-model="username"> <button v-click="text"></button> <router-view></router-view> </div> </div> </template>
4、最後就是新建hello、header、product這幾個組件來驗證我們的效果,這裏就不做演示了,因為我自己已經測試過了,沒有問題
vue-router2.0二級路由的簡單使用