詳解vue-router 命名路由和命名視圖
更新時間:2018年06月01日 08:32:55 作者:侯婧歡
這篇文章主要介紹了詳解vue-router 命名路由和命名視圖,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
說明:vue-router的幾個文章中例子是連貫的,因此對哪塊有疑問請翻閱按發(fā)表時間排序的其他文章。
一、概述
- 給路由定義不同的名字,根據(jù)名字進行匹配
- 給不同的router-view定義名字,router-link通過名字進行對應(yīng)組件的渲染。
二、代碼展示:
目錄視圖

1、命名路由
2、命名視圖
index.js
import Vue from 'vue'
import Router from 'vue-router'
import Goodlists from '@/Goodlists/goods'
import Title from '@/Goodlists/title'
import Img from '@/Goodlists/img'
import Cart from '@/Goodlists/cart'
Vue.use(Router)
export default new Router({
routes: [
{
path: '/goods',
name: 'Goodlists',
components:{
default:Goodlists,
title:Title,
image:Img,
}
}
]
})
App.vue
<template>
<div id="app">
<img src="./assets/logo.png">
<router-view></router-view>
<router-view name="title" class="left"></router-view>
<router-view name="image" class="right"></router-view>
</div>
</template>
<script>
export default {
name: 'app'
}
</script>
<style>
#app {
font-family: 'Avenir', Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
margin-top: 60px;
}
.left,.right{
float: left;
width:48%;
text-align: center;
border:1px solid red
}
</style>

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Luckysheet?在vue中離線使用及引入報錯的解決方案(推薦)
這篇文章主要介紹了Luckysheet?在vue中離線使用方法及引入報錯的解決方案,將dist離線包在項目創(chuàng)建個文件夾放著,然后根據(jù)放置的位置在?index.html里面引入,下面通過案例給大家介紹我的項目里面放置的位置,需要的朋友可以參考下2022-10-10
vue動態(tài)綁定多個class以及帶上三元運算或其他條件
這篇文章主要介紹了vue動態(tài)綁定多個class以及帶上三元運算或其他條件,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-04-04

