vue3+ts keep-alive缓存机制

<template lang="html">
  <div>
    <el-button type="primary" @click="flag = !flag">切换组件</el-button>
    <keep-alive :include="['A']">
      <A v-if="flag"></A>
      <B v-else></B>
    </keep-alive>
  </div>
</template>
<script lang="ts" setup>
import { ref, reactive } from "vue";
import A from "./components/A.vue";
import B from "./components/B.vue";

const flag = ref<Boolean>(true);
</script>
<style lang="scss"></style>

你可能感兴趣的:(缓存,vue.js,前端)