详解vue-router 命名路由和命名视图
2018-06-01 08:32
981 查看
说明:vue-router的几个文章中例子是连贯的,因此对哪块有疑问请翻阅按发表时间排序的其他文章。
一、概述
- 给路由定义不同的名字,根据名字进行匹配
- 给不同的router-view定义名字,router-link通过名字进行对应组件的渲染。
二、代码展示:
目录视图
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>
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。
您可能感兴趣的文章:
相关文章推荐
- vue + vue-router路由视图命名+路由嵌套
- vue-router -- 命名路由和命名视图
- VueJs(11)---vue-router(命名路由,命名视图,重定向别名,路由组件传参)
- 第五,vue-router命名路由和命名视图(以及学完vue-router总结)
- 讲解vue-router之命名路由和命名视图
- VueJs路由跳转——vue-router的使用详解
- 详解vue-router2.0动态路由获取参数
- Vue.js路由组件vue-router使用方法详解
- vue-router 路由基础的详解
- [置顶] 跟我学AngularJs:router路由与多重视图详解
- AngularJS:router路由与多重视图详解
- vue-router命名视图
- Vue-router的使用和出现空白页,路由对象属性详解
- vue-router 之命名路由
- vue-router菜鸟进阶!(嵌套路由VS命名路由)
- 详解windows下vue-cli及webpack 构建网站(四) 路由vue-router的使用
- Vue.js路由vue-router使用方法详解
- AngularJs:router路由与多重视图详解
- 详解Vue.js搭建路由报错 router.map is not a function
- vue-router命名路由