本文介绍: eltabs 使用时会一次性把所有 tab 里的请求读完,之后进行 tab 切换,不再重新读取请求 想要实现切换 tab通过以下代码实现实时更新数据的要求。分别为自定义tab页面

eltabs 使用时会一次性把所有 tab 里的请求读完,之后进行 tab 切换,不再重新读取请求 想要实现切换 tab通过以下代码实现实时更新数据的要求

<template>
  <el-tabs type="border-card" @tab-click="handleTabClick" v-model="activeName">
      <el-tab-pane :label="t('customer.all')" name="all">
            <div v-if="tabRefresh.all">
                    <AllCustomerIndex />      
            </div>    
      </el-tab-pane>    
      <el-tab-pane :label="t('customer.oneself')" name="oneself">      
            <div v-if="tabRefresh.oneself">
                    <MyCustomerIndex />      
            </div>    
      </el-tab-pane>
      <el-tab-pane :label="t('customer.belong')" name="belong">
            <div v-if="tabRefresh.belong">
                    <BelongCustomerIndex />      
            </div>    
      </el-tab-pane>  
   </el-tabs>
</template>

其中 

<AllCustomerIndex /> 、<MyCustomerIndex />   、<BelongCustomerIndex />

分别为自定义的tab子页面。即为表格页面

// 切换tab自动刷新实现
const activeName = ref('all')
const tabRefresh = reactive<TabRefresh>({
  all: true,
  oneself: false,
  belong: false
})
const handleTabClick = async (tab) => {
  activeName.value = tab.props.name
  switch (activeName.value) {
      case 'all':      
          await switchTab('all')      
          break    
      case 'oneself':      
          await switchTab('oneself')      
          break    
      case 'belong':      
          await switchTab('belong')      
          break  
   }}
   const switchTab = async (tab) => {
     Object.keys(tabRefresh).forEach((k) => {
         tabRefresh[k as keyof TabRefresh] = tab == k  
     })
  }

其中TabRefresh为自定义类型

export type TabRefresh = { all: boolean oneself: boolean belong: boolean }

export type TabRefresh = {
  all: boolean  
  oneself: boolean  
  belong: boolean
}

 

原文地址:https://blog.csdn.net/qq_34431921/article/details/130701486

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任

如若转载,请注明出处:http://www.7code.cn/show_32418.html

如若内容造成侵权/违法违规/事实不符,请联系代码007邮箱suwngjj01@126.com进行投诉反馈,一经查实,立即删除

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注