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 ...
随机推荐
- LCD 调试总结
转自:http://blog.csdn.net/qikaibinglan/article/details/5630246 (1) 液晶显示模式 并行:MCU接口.RGB接口.Vysnc接口 串行:SP ...
- java基础之JDBC七:C3P0连接池的使用
使用C3P0的前提是需要引入jar包 具体使用如下: /** * c3p0的应用 * 前提:引入c3p0的jar包 */ public class Test { public static void ...
- Log4j配置很详细
来自: http://www.blogjava.net/zJun/archive/2006/06/28/55511.html Log4J的配置文件(Configuration File)就是用来设置记 ...
- Opencv图像变成灰度图像、取反图像
#include <iostream>#include <opencv2/opencv.hpp> using namespace cv;using namespace std; ...
- ubuntu16.04 安装openpose
安装 Anaconda3 Tensorflow-cpu python3tensorflow 1.4.1+opencv3, protobuf, python3-tk ================== ...
- 345. Reverse Vowels of a String翻转字符串中的元音字母
[抄题]: Write a function that takes a string as input and reverse only the vowels of a string. Example ...
- 使用RVM更新Ruby 版本
http://rvm.io/rvm/install Install RVM (development version): \curl -sSL https://get.rvm.io | bash Wi ...
- SqlServer—大话函数依赖与范式
说明:数据库中的某些概念真的很让人头疼,概念的东西本来就是很枯燥的,再加上枯燥的学习,那就更加枯燥了.概念这东西,你不理解也能生产东西,经验多了就行,但是为了更深入的学习,你还必须理解.这里,我抛开书 ...
- laravel的orm增删改查
增: //通过模型新增 //使用模型的create方法新增数据 删: //通过模型删除 //通过主键删除 改: //通过模型更新数据库 //结合查询语句批量更新 查:
- Flask框架 之 上下文管理前戏
偏函数 自动传递参数 import functools def index(a1,a2): return a1 + a2 # 原来的调用方式 # ret = index(1,23) # print(r ...