quasar框架切换Tab页使用<keep-alive>缓存

写法1 : 使用quasar的q-tabs组件使用方法

typescript 复制代码
//布局样式根据需求自己设置
<template>
	<div class="all-Tabs">
		 <q-tabs v-model="activeTabName"  @update:model-value="selectedChange">
		   <q-tab
		     v-for="(item, index) in cardArr"
		     :key="index"
		     :label="item.label"
		     :name="item.activeTabName"></q-tab>
		 </q-tabs>
		 <div class="bottom">
		    <!-- 放置动态组件... -->
            <!-- keep-alive缓存组件,这样的话,组件就不会被销毁,DOM就不会被重新渲染 -->
		  	<keep-alive>
				 <component
				     :is="activeTabName"
				   ></component>
			</keep-alive>
		 </div>
</div>
</template>
<script>
import { ref, shallowRef, watch, nextTick, onMounted, inject,reactive ,computed,toRefs,getCurrentInstance,onUnmounted,watchEffect} from 'vue'
import hourlyQueryCom from './hourlyQueryCom'
import journalQueryCom from './journalQueryCom'
import historicalDataCom from './historicalDataCom'
import historicalDataMoreCom from './historicalDataMoreCom'
export default {
  name: "index",
  components:{
    hourlyQueryCom,
    journalQueryCom,
    historicalDataCom,
    historicalDataMoreCom
  },
   setup(){
   	 const state = reactive({
      activeTabName:'hourlyQueryCom',
      cardArr: [
        {
          label: "观测部查询",
          activeTabName: "hourlyQueryCom",
        },
        {
          label: "日纪要查询",
          activeTabName: "journalQueryCom",
        },
        {
          label: "历史数据单表查询",
          activeTabName: "historicalDataCom",
        },
        {
          label: "历史数据多表查询",
          activeTabName: "historicalDataMoreCom",
        },
      ],
    })
    
	 const selectedChange = (value)=>{
	      state.activeTabName = value
	 }
   return{
   selectedChange,
	...toRefs(state),
	}
   }
</script>

写法2 :手动创建tab切换效果

typescript 复制代码
//自行设置样式
<template>
  <div class="all-Tabs">
      <div class="top">
        <div class="crad"
             :class="{ highLight: whichIndex == index }"
             v-for="(item, index) in cardArr"
             :key="index"
             @click="
             whichIndex = index;
             activeTabName = item.activeTabName;
          ">
          {{ item.label }}
        </div>
      </div>
      <div class="bottom">
        <!-- 放置动态组件... -->
        <!-- keep-alive缓存组件,这样的话,组件就不会被销毁,DOM就不会被重新渲染 -->
        <keep-alive>
          <component :is="activeTabName"></component>
        </keep-alive>
     </div>
  </div>
</template>
<script>
import { ref, shallowRef, watch, nextTick, onMounted, inject,reactive ,computed,toRefs,getCurrentInstance,onUnmounted,watchEffect} from 'vue'
import hourlyQueryCom from './hourlyQueryCom'
import journalQueryCom from './journalQueryCom'
import historicalDataCom from './historicalDataCom'
import historicalDataMoreCom from './historicalDataMoreCom'
export default {
  name: "index",
  components:{
    hourlyQueryCom,
    journalQueryCom,
    historicalDataCom,
    historicalDataMoreCom
  },
   setup(){
   	 const state = reactive({
      whichIndex:0,
      activeTabName:'hourlyQueryCom',
      cardArr: [
        {
          label: "观测部查询",
          activeTabName: "hourlyQueryCom",
        },
        {
          label: "日纪要查询",
          activeTabName: "journalQueryCom",
        },
        {
          label: "历史数据单表查询",
          activeTabName: "historicalDataCom",
        },
        {
          label: "历史数据多表查询",
          activeTabName: "historicalDataMoreCom",
        },
      ],
    })
  
   return{
	...toRefs(state),
	}
   }
</script>
<style  scoped lang="scss">
	.highLight{
		border:1px solid red;///自行设置  高亮	
	}
	//自行设置样式
	.bottom{
		
	}
</style>
相关推荐
Zfox_14 小时前
Redis:Hash数据类型
服务器·数据库·redis·缓存·微服务·哈希算法
呼拉拉呼拉14 小时前
Redis内存淘汰策略
redis·缓存
咖啡啡不加糖18 小时前
Redis大key产生、排查与优化实践
java·数据库·redis·后端·缓存
肥仔哥哥193019 小时前
springCloud2025+springBoot3.5.0+Nacos集成redis从nacos拉配置起服务
redis·缓存·最新boot3集成
呼拉拉呼拉1 天前
Redis故障转移
数据库·redis·缓存·高可用架构
篱笆院的狗1 天前
如何使用 Redis 快速实现布隆过滤器?
数据库·redis·缓存
Alla T1 天前
【前端】缓存相关
前端·缓存
chen.@-@1 天前
后端下载限速(redis记录实时并发,bucket4j动态限速)
数据库·redis·缓存
吾日三省吾码1 天前
Spring 团队详解:AOT 缓存实践、JSpecify 空指针安全与支持策略升级
java·spring·缓存
不凡的凡2 天前
鸿蒙图片缓存(一)
缓存