詳解vue-router 命名路由和命名視圖
說明:vue-router的幾個(gè)文章中例子是連貫的,因此對(duì)哪塊有疑問請(qǐng)翻閱按發(fā)表時(shí)間排序的其他文章。
一、概述
- 給路由定義不同的名字,根據(jù)名字進(jìn)行匹配
- 給不同的router-view定義名字,router-link通過名字進(jìn)行對(duì)應(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)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Vue router的addRoute方法實(shí)現(xiàn)控制權(quán)限方法詳解
這篇文章主要介紹了vue動(dòng)態(tài)路由添加,vue-router的addRoute方法實(shí)現(xiàn)權(quán)限控制流程,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧2022-09-09vue數(shù)組對(duì)象排序的實(shí)現(xiàn)代碼
這篇文章主要介紹了vue數(shù)組對(duì)象排序的實(shí)現(xiàn)代碼,這里整理了詳細(xì)的代碼,非常具有實(shí)用價(jià)值,需要的朋友可以參考下2018-06-06vue的注意規(guī)范之v-if 與 v-for 一起使用教程
這篇文章主要介紹了vue的注意規(guī)范之v-if 與 v-for 一起使用方法,本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-08-08vue-router兩種模式區(qū)別及使用注意事項(xiàng)詳解
這篇文章主要介紹了vue-router兩種模式區(qū)別及使用注意事項(xiàng),結(jié)合實(shí)例形式詳細(xì)分析了vue-router兩種模式hash模式與history模式的區(qū)別、用法與操作注意事項(xiàng),需要的朋友可以參考下2019-08-08Ant Design Vue Pro靜態(tài)路由如何改為動(dòng)態(tài)路由
這篇文章主要介紹了Ant Design Vue Pro靜態(tài)路由如何改為動(dòng)態(tài)路由問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-10-10vuejs實(shí)現(xiàn)ready函數(shù)加載完之后執(zhí)行某個(gè)函數(shù)的方法
這篇文章主要介紹了vuejs實(shí)現(xiàn)ready函數(shù)加載完之后執(zhí)行某個(gè)函數(shù)的方法,需要的朋友可以參考下2018-08-08