用组件的方法搭建element ui tabs以及tabs的刷新处理

本文介绍了如何使用Vue组件来搭建Element UI的tabs功能,并解决父组件将子组件作为弹窗调用时,子组件只执行一次created问题。通过在父组件中引入并注册子组件,利用`v-if`和`v-show`控制组件的显示与刷新,以及在父组件中提供`reload`方法,实现在切换tab时子组件的刷新。此外,还展示了如何在子组件中注入并调用`reload`方法以达到重新渲染的效果。
摘要由CSDN通过智能技术生成

用组件的方法搭建

HTML

<el-container>
     <el-main>
	  	<template>
	    	<el-tabs v-model="activeName" @tab-click="handleClick" v-show="showtab"  >
	        	<el-tab-pane  v-for="(page, index) in pages"   v-bind:key="index"   :label="page.label"   :name="page.name"  >
	          		<!--循环生成子页面-->
	           		 <components :is="page.name" v-if="page.name == nowPage"></components>
	         	</el-tab-pane>
	    	</el-tabs>
	  </template>
  	</el-main>
</el-container>

VUE


// 导入相关的路由
import CasePage from '@/components/outpatientDoctor/CasePage.vue'
import InspectionApplication from '@/components/outpatientDoctor/InspectionApplication.vue'
import CheckOutApplication from '@/components/outpatientDoctor/CheckOutApplication.vue'
import OutpatientDiagnosis from '@/components/outpatientDoctor/OutpatientDiagnosis.vue'	
import DisposalApplication from '@/components/outpatientDoctor/DisposalApplication.vue'
import PatentPrescription from '@/components/outpatientDoctor/PatentPrescription.vue'	
import HerbalPrescription from '@/components/outpatientDoctor/HerbalPrescription.vue'
import AfterDiagnosis from '@/components/outpatientDoctor/AfterDiagnosis.vue'
import ExpenseQuery from '@/components/registerCharge/expenseQuery.vue'
	
export default {
	name: 'tabZujian',
	components:{
		CasePage,
		InspectionApplication,
		CheckOutApplication,
		OutpatientDiagnosis,
		DisposalApplication,
		PatentPrescription,
		HerbalPrescription,
		AfterDiagnosis,
		ExpenseQuery
	},
    data() {
		return {
			activeName: "casePage",//第一个加载的页面
			nowPage: "casePage",
			showtab:false,
			pages: [
				//所有子页面信息
				 {name: "casePage",label: "病例首页"},
				 {name: "inspectionApplication",label: "检查申请"},
				 {name: "checkOutApplication",label: "检验申请"},
				 {name: "outpatientDiagnosis",label: "门诊确诊"},
				 {name: "disposalApplication",label: "处置申请"},
				 {name: "patentPrescription",label: "成药处方"},
				 {name: "herbalPrescription",label: "草药处方"},
				 {name: "afterDiagnosis",label: "诊毕"},
				 {name: "expenseQuery",label: "费用查询"}
			 ]
		}
    },
     methods: {
		handleClick(tab, event) {
			this.nowPage=tab.name
		}
	}
}	

组件刷新

用组件的方法搭建element ui tabs

HTML

在这里插入图片描述

<el-container>
     <el-main>
	  	<template>
	    	<el-tabs v-model="activeName" @tab-click="handleClick" v-show="showtab" >
	        	<el-tab-pane  v-for="(page, index) in pages"   v-bind:key="index"   :label="page.label"   :name="page.name"  v-if="isRouterAlive">
	          		<!--循环生成子页面-->
	           		 <components :is="page.name" v-if="page.name == nowPage"></components>
	         	</el-tab-pane>
	    	</el-tabs>
	  </template>
  	</el-main>
</el-container>

VUE

在这里插入图片描述

在这里插入图片描述


// 导入相关的路由
import CasePage from '@/components/outpatientDoctor/CasePage.vue'
import InspectionApplication from '@/components/outpatientDoctor/InspectionApplication.vue'
import CheckOutApplication from '@/components/outpatientDoctor/CheckOutApplication.vue'
import OutpatientDiagnosis from '@/components/outpatientDoctor/OutpatientDiagnosis.vue'	
import DisposalApplication from '@/components/outpatientDoctor/DisposalApplication.vue'
import PatentPrescription from '@/components/outpatientDoctor/PatentPrescription.vue'	
import HerbalPrescription from '@/components/outpatientDoctor/HerbalPrescription.vue'
import AfterDiagnosis from '@/components/outpatientDoctor/AfterDiagnosis.vue'
import ExpenseQuery from '@/components/registerCharge/expenseQuery.vue'
	
export default {
	name: 'tabZujian',
	components:{
		CasePage,
		InspectionApplication,
		CheckOutApplication,
		OutpatientDiagnosis,
		DisposalApplication,
		PatentPrescription,
		HerbalPrescription,
		AfterDiagnosis,
		ExpenseQuery
	},
	provide () {                        
		return {
			reload: this.reload                                              
		}
	},
    data() {
		return {
			isRouterAlive: true ,
			activeName: "casePage",//第一个加载的页面
			nowPage: "casePage",
			showtab:false,
			pages: [
				//所有子页面信息
				 {name: "casePage",label: "病例首页"},
				 {name: "inspectionApplication",label: "检查申请"},
				 {name: "checkOutApplication",label: "检验申请"},
				 {name: "outpatientDiagnosis",label: "门诊确诊"},
				 {name: "disposalApplication",label: "处置申请"},
				 {name: "patentPrescription",label: "成药处方"},
				 {name: "herbalPrescription",label: "草药处方"},
				 {name: "afterDiagnosis",label: "诊毕"},
				 {name: "expenseQuery",label: "费用查询"}
			 ]
		}
    },
     methods: {
     	reload () {
			this.isRouterAlive = false;            //先关闭,
			this.$nextTick(function () {
				this.isRouterAlive = true;         //再打开
			}) 
		},
		handleClick(tab, event) {
			this.nowPage=tab.name
		}
	}
}	

在对应的tab组件中写

export default {
    inject:['reload'],  //注入App里的reload方法
    data () {
        return {
    	.......
        }
    },

在方法块中调用

this.reload();

解决父组件将子组件作为弹窗调用只执行一次created的问题

第一调用渲染子组件后,不再对子组件的created进行调用

在这里插入图片描述
在这里插入图片描述

使用

this.dialogVisible1=true
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值