vue 在路由中复用组件
首先需要在app.vue中引入:
<template>
<div id="app">
<!--<app-header></app-header>-->
<div class="container">
<app-header></app-header>
</div>
<div class="container">
<router-view></router-view>
</div>
<br>
<div class="container">
<div class="row">
<div class="col-sm-12 col-md-4">
<router-view name ="orderingGuide"></router-view>
</div> <div class="col-sm-12 col-md-4">
<router-view name ="delivery"></router-view>
</div> <div class="col-sm-12 col-md-4">
<router-view name ="history"></router-view>
</div>
</div>
</div>
</div>
</template> <script>
import Header from './components/Header';
export default {
components:{
appHeader:Header
}
}
</script> <style> </style>

然后再main.js中引入:
import Home from './components/Home'
import Menu from './components/Menu'
import Login from './components/Login'
import Register from './components/Register'
import Admin from './components/Admin'
import About from './components/about/About' //二级路由
import Contact from './components/about/Contact'
import History from './components/about/History'
import Delivery from './components/about/Delivery'
import OrderingGuide from './components/about/OrderingGuide'
//三级路由
import Phone from './components/about/contact/Phone'
import PersonName from './components/about/contact/PersonName' export const routes = [
{path:'/',name:'homeLink',components:{
default:Home,
'orderingGuide':OrderingGuide,
'delivery':Delivery,
'history':History
}},
{path:'/menu',component:Menu},
{path:'/admin',component:Admin/*,beforeEnter:(to,from,next) =>{
if(to.path =='login'||to.path =='register'){
next();
}else{
alert("haimeit1");
next('/login');
}
}*/},
{path:'/register',component:Register},
{path:'/about',component:About,redirect:'/about/contact',children:[
{path:'/about/contact' ,name:"contactLink",component:Contact ,redirect:'/phone',children: [
{path:'/phone',name:"phoneNum",component:Phone},
{path:'/personName',name:"personName",component:PersonName}
]},
{path:'/history' ,name:"historyLink",component:History},
{path:'/about/delivery' ,name:"deliveryLink",component:Delivery},
{path:'/about/orderingGuide' ,name:"orderingGuideLink",component:OrderingGuide}
]},
{path:'/login',component:Login},
{path:'*',redirect:Home}, ]

最终展示效果:

vue 在路由中复用组件的更多相关文章
- vue获取路由中的值
vue中获取路由中的值 在vue中如何获取路由中的值呢?大家先看下面这段代码: this.$route.params && this.$route.params.id 这行代码就是在v ...
- vue.js 1中父组件跳到子组件中并传参让子组件显示不同的内容
父组件中的点击跳转: <ul class="insurance-entry clearfloat"> <li v-link="{name:'produc ...
- vue封装element中table组件
后台系统,table被用的次数比较多,所以决定提出来作为组件 1.新建一个Table.vue文件 <!--region 封装的分页 table--> <template> & ...
- vue+element ui中select组件选择失效问题原因与解决方法
codejing 2020-07-10 09:13:31 652 收藏 分类专栏: Web Vue Element UI 版权 .当表单form赋完值后,如果后续又对form中某一属性值进行操作如 ...
- 关于vue项目 路由中 使用的坑
关于vue路由重定向的时候 记得一定要先声明先声明
- vue 去掉路由中的#
在router.js中修改, const router = new VueRouter({ mode: 'history', routes: [...] })
- vue --》elementUI 中 el-table组件 如何实现点击列,让该列高亮显示 ?
在elmentui官网中,只给了让当前行高亮显示的方法,但是如何让当前列高亮显示呢? <template> <div> <el-table :data="tab ...
- script标签引入vue方式开发如何写组件
title: script标签引入vue方式开发如何写组件 date: 2020-05-08 sidebarDepth: 2 tags: vue 组件 script 标签 categories: vu ...
- vue中的组件,Component元素,自定义路由,异步数据获取
组件是Vue最强大的功能之一.组件是一组可被复用的具有一定功能,独立的完整的代码片段,这个代码片段可以渲染一个完整视图结构组件开发如何注册组件?第一步,在页面HTML标签中使用这个组件名称,像使用DO ...
随机推荐
- 在ubuntu中安装minicom时出现devic…
未正常关闭minicom yesaidu@ywf-ubuntu: ~$ ls /var/lock LCK..ttyS0 subsys yesaidu@ywf-ubuntu: ~$ kill 0 ye ...
- ionic中隐藏header
设置ion-view标签的hide-nav-bar属性为true <ion-view hide-nav-bar="true"> <ion-content> ...
- libevent源码深度剖析五
libevent源码深度剖析五 ——libevent的核心:事件event 张亮 对事件处理流程有了高层的认识后,本节将详细介绍libevent的核心结构event,以及libevent对event的 ...
- Linux vi的基本操作
进入命令 vi <文件名> 如 vi test 如果test文件存在,则直接打开编辑.如果不存在,则新建一个test的文件,这个新建的文件如果不保存的话,退出编辑器后也不会保存到硬盘中. ...
- IWebBrowser2不能复制剪切
项目中嵌入了IE控件,近期做了一次大改版,发现网页不能进行复制和剪切了,折腾了半天,发现是com初始化有问题: 修正前的方式: CoInitialize(NULL); // do your work ...
- sam格式详细说明
原文链接 https://www.jianshu.com/p/386f520e5de1 The SAM Format Specification(sam格式说明) 1 The SAM Format S ...
- hdu 4768 Flyer (异或操作的应用)
2013年长春网络赛1010题 继巴斯博弈(30分钟)签到后,有一道必过题(一眼即有思路). 思路老早就有(40分钟):倒是直到3小时后才被A掉.期间各种换代码姿态! 共享思路: unlucky st ...
- [GO]指针和函数配合的值传递
package main import "fmt" func swap(a, b int) { a, b = b, a fmt.Printf("a = %d, b = % ...
- HTML5拓扑3D机房,电力工控Web SCADA
http://www.hightopo.com/cn-index.html 一套丰富的JavaScript界面类库, 提供完整的基于HTML5图形界面组件库.使用HT for Web您可以轻松构建现代 ...
- 编写高质量代码改善C#程序的157个建议——建议45:为泛型类型参数指定逆变
建议45:为泛型类型参数指定逆变 逆变是指方法的参数可以是委托或者泛型接口的参数类型的基类.FCL4.0中支持逆变的常用委托有: Func<int T,out TResult> Predi ...