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 ...
随机推荐
- QQ、邮箱、手机号 正则验证
邮箱:/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/ 手机号:/^(((13[0-9]{1})|(15[0-9]{1 ...
- UIRect中的Anchor组件
[UIRect中的Anchor组件] Anchor用于实现粘着功能,寄存于UIRect类中.Anchor的类型有三种: 1.None:不使用跟随功能. 2.Unified:四条边使用相同的Target ...
- jQuery简单介绍及基本用法(选择器&DOM操作)
简介 jQuery是一个快速.简洁的JavaScript框架,是继Prototype之后又一个优秀的JavaScript代码库(或JavaScript框架).jQuery设计的宗旨是“write Le ...
- HandleErrorAttribute
前言 一直在给Team的人强调“Good programming is good Error Handling”,没人喜欢YSOD(Yellow Screen of Death).我每次看到黄页的时候 ...
- opennebula 创建镜像数据块
{","csrftoken":"f5454a02dea7b4a7d5d50b482a762b57"}
- c# 下实现ping 命令操作
1>通过.net提供的类实现 using System; using System.Collections.Generic; using System.Linq; using System.Te ...
- 23、sed常用命令
1.匹配与不匹配: n p ! sed -n '/ATTGC/p' file1 ##-n打印匹配到的行输出,默认所有行输出. sed -n '/AT\|GC/p' fil ...
- pandas map, apply, applymap区别
map只对一个序列而言的. apply只是整个dataframe上任意一列或多列,或者一行或多行, 即可在任意轴操作. 在一列使用apply时,跟map效果一样. 多列时只能用apply. apply ...
- 清除Vs2010的工作区影射关系的缓存信息的文件夹路径
C:/Users/Administrator/AppData/Local/Microsoft/Team Foundation/3.0/Cache
- Robot Framework - 常用断言讲解
RobotFramework带有丰富的系统关键,使用时无需导入,直接使用,为写自动化用例带来了极大的方便:不能停留在知道或者是会得程度,只有熟练使用各关键字,才能提升自动化用例的写作效率. 下面将逐个 ...