第一種方法:vue嵌套路由(二)
<el-menu :default-active="defaultActive" style="min-height: 100%;" theme="dark" router> <el-menu-item index="manage"> <i class="el-icon-menu"></i>首頁 </el-menu-item> <el-submenu index='2'> <template slot='title'> <i class="el-icon-document"></i>用戶管理 </template> <el-menu-item index="userList">用戶查詢</el-menu-item> <el-menu-item index="userforbid">封號管理</el-menu-item> <el-menu-item index="userapply">用戶申請</el-menu-item> </el-submenu> </el-menu>
<el-col :span="20" style="min-height:100%;background:#F2F4F8">
<router-view></router-view>
</el-col>
在js中
{ path:'/manage', component: manage, name:'', children:[{ path:'/userList', component:userList, meta: ['用戶列表'] }] }
當我們點擊用戶查詢時,就會跳轉到http://localhost:8080/#/userList
第二種方法點擊事件
<el-button :plain="true" type="success" @click="goadd"> goadd(){ this.$router.push({ path: '/addcategory' }) }
第三種方法命名路由:
<div id="app"> <h1>Named Routes</h1> <p>Current route name: {{ $route.name }}</p> <ul> <li><router-link :to="{ name: 'home' }">home</router-link></li> <li><router-link :to="{ name: 'foo' }">foo</router-link></li> <li><router-link :to="{ name: 'bar', params: { id: 123 }}">bar</router-link></li> </ul> <router-view class="view"></router-view> </div> <template id='home'> <div>This is Home</div> </template> <template id='foo'> <div>This is Foo</div> </template> <template id='bar'> <div>This is Bar {{ $route.params.id }}</div> </template> const Home = { template: '#home' }; const Foo = { template: '#foo' }; const Bar = { template: '#bar' }; const router = new VueRouter({ routes: [ { path: '/', name: 'home', component: Home }, { path: '/foo', name: 'foo', component: Foo }, { path: '/bar/:id', name: 'bar', component: Bar } ] }); new Vue({ router:router }).$mount('#app');
第四種方法命名視圖:
<div id="app"> <router-link to="/">Go to Foo</router-link> <router-view class="view one"></router-view> <router-view class="view two" name="a"></router-view> <router-view class="view three" name="b"></router-view> </div> <template id='foo'> <div>This is Foo</div> </template> <template id='bar'> <div>This is Bar {{ $route.params.id }}</div> </template> <template id='baz'> <div>This is baz</div> </template> const Foo = { template: '#foo' }; const Bar = { template: '#bar' }; const Baz = { template: '#baz' }; const router = new VueRouter({ routes: [ { path: '/', components: { default:Foo, a:Bar, b:Baz } } ] }); new Vue({ router:router }).$mount('#app');
第五種方法
<div id="app"> <h1>Hello App!</h1> <p> <!-- 使用 router-link 組件來導航. --> <!-- 通過傳入 `to` 屬性指定鏈接. --> <!-- <router-link> 默認會被渲染成一個 `<a>` 標簽 --> <router-link to="/foo">Go to Foo</router-link> <router-link to="/bar">Go to Bar</router-link> </p> <!-- 路由出口 --> <!-- 路由匹配到的組件將渲染在這里 --> <router-view></router-view> </div> <template id='foo'> <p>this is foo!</p> </template> <template id='bar'> <p>this is bar!</p> </template> // 1. 定義(路由)組件。 // 可以從其他文件 import 進來 const Foo = { template:'#foo' }; const Bar = { template:'#bar' }; // 2. 定義路由 // 每個路由應該映射一個組件。 其中"component" 可以是 // 通過 Vue.extend() 創建的組件構造器, // 或者,只是一個組件配置對象。 const routes = [ { path: '/foo', component: Foo }, { path: '/bar', component: Bar } ]; // 3. 創建 router 實例,然后傳 `routes` 配置 // 你還可以傳別的配置參數, 不過先這么簡單着吧。 const router = new VueRouter({ routes:routes }); // 4. 創建和掛載根實例。 // 記得要通過 router 配置參數注入路由, // 從而讓整個應用都有路由功能 const app = new Vue({ router:router }).$mount('#app');
引:http://blog.csdn.net/bboyjoe/article/details/52804988