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>
相关推荐
泽韦德2 小时前
【Redis】笔记|第10节|京东HotKey实现多级缓存架构
redis·笔记·缓存
麓殇⊙5 小时前
redis--黑马点评--Redisson快速入门
数据库·redis·缓存
whltaoin7 小时前
Redis专题-实战篇一-基于Session和Redis实现登录业务
redis·缓存·springboot
华清远见成都中心9 小时前
大语言模型(LLM)中的KV缓存压缩与动态稀疏注意力机制设计
人工智能·缓存·语言模型
张哈大10 小时前
【 java 虚拟机知识 第一篇 】
java·开发语言·jvm·笔记·缓存
伤不起bb15 小时前
Redis 哨兵模式
数据库·redis·缓存
迪迦不喝可乐15 小时前
Redis 知识点一
redis·缓存
呼拉拉呼拉15 小时前
Redis知识体系
数据库·redis·缓存·知识体系
霖檬ing15 小时前
Redis——主从&哨兵配置
数据库·redis·缓存
卜及中18 小时前
【Redis/2】核心特性、应用场景与安装配置
数据库·redis·缓存