提交 b7cf1fb3 编写于 作者: B big_sun_962464

Fri Jul 12 15:18:00 CST 2024 inscode

上级 25abec2c
<script setup> <script setup>
import Com1 from './components/Com1.vue' import Com1 from './components/Com1.vue'
import Com2 from './components/Com2.vue' import Com2 from './components/Com2.vue'
import {onMounted, toRefs,watchEffect,shallowReadonly,readonly,ref,reactive,shallowRef,computed, isRef, unref, toRef, toValue, watch, onBeforeMount, onBeforeUpdate, onUpdated} from 'vue' import { onMounted, toRefs, watchEffect, shallowReadonly, readonly, ref, reactive, shallowRef, computed, isRef, unref, toRef, toValue, watch, onBeforeMount, onBeforeUpdate, onUpdated } from 'vue'
const tabs = { const tabs = {
Com1, Com1,
Com2 Com2
} }
const currentObj = ref({ const currentObj = ref({
tab:Com1, tab: Com1,
key:'Com1' key: 'Com1'
}) })
function changeCom(k, v) {
function changeCom(k,v){
currentObj.value.key = k currentObj.value.key = k
currentObj.value.tab = v currentObj.value.tab = v
} }
const isAddKeepAlive = ref(false)
</script> </script>
<template> <template>
<button v-for="(v,k) in tabs" :key="k" @click="changeCom(k,v)">{{ k }}</button> <p>
<component :is="currentObj.tab"></component> <button @click="isAddKeepAlive = !isAddKeepAlive">是否添加KeepAlive-{{ isAddKeepAlive }}</button>
</p>
<button v-for="(v, k) in tabs" :key="k" @click="changeCom(k, v)">{{ k }}</button>
<KeepAlive v-if="isAddKeepAlive">
<component :is="currentObj.tab"></component>
</KeepAlive>
<component v-else :is="currentObj.tab"></component>
</template> </template>
<style scoped> <style scoped></style>
\ No newline at end of file
</style>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册