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>
相关推荐
心勤则明34 分钟前
Spring AI 会话记忆实战:从内存存储到 MySQL + Redis 双层缓存架构
人工智能·spring·缓存
Lisonseekpan11 小时前
Guava Cache 高性能本地缓存库详解与使用案例
java·spring boot·后端·缓存·guava
我真的是大笨蛋11 小时前
Redis的String详解
java·数据库·spring boot·redis·spring·缓存
低调小一13 小时前
LRU缓存科普与实现(Kotlin 与 Swift)
开发语言·缓存·kotlin
伐尘15 小时前
【计算机】常见的缓存和查看方法
缓存·电脑·笔记本
我梦之615 小时前
libevent输出缓存区的数据
服务器·网络·c++·缓存
兜兜风d'17 小时前
redis字符串命令
数据库·redis·缓存
野犬寒鸦19 小时前
从零起步学习Redis || 第十二章:Redis Cluster集群如何解决Redis单机模式的性能瓶颈及高可用分布式部署方案详解
java·数据库·redis·后端·缓存
悟能不能悟1 天前
redis的红锁
数据库·redis·缓存
酷ku的森1 天前
Redis的缓存更新策略
缓存