首页 > 其他分享 >keep-alive

keep-alive

时间:2022-08-23 09:58:31浏览次数:70  
标签:console log alive keep Home home

父组件 : 

<template>
  <div class="app">
    <div class="view">
      <!-- include: 组件的名称来自于组件定义时name选项  -->
      <keep-alive include="home,about">
        <component :is="currentTab"></component>
      </keep-alive>
    </div>
  </div>
</template>

<script>
  import Home from './views/Home.vue'
  import About from './views/About.vue'
  import Category from './views/Category.vue'

  export default {
    components: {
      Home,
      About,
      Category
    },
    data() {
      return {
        tabs: ["home", "about", "category"],
        // currentIndex: 0
        currentTab: "home"
      }
    },
    methods: {
      itemClick(tab) {
        this.currentTab = tab
      },
      homeClick(payload) {
        console.log("homeClick:", payload)
      }
    }
  }
</script>

<style scoped>
  .active {
    color: red;
  }
</style>
子组件 : 


<template>
  <div>
    <h2>Home组件</h2>
    <h2>当前计数: {{ counter }}</h2>
    <button @click="counter++">+1</button>
  </div>
</template>

<script>
  export default {
    name: "home",
    data() {
      return {
        counter: 0
      }
    },
    created() {
      console.log("home created")
    },
    unmounted() {
      console.log("home unmounted")
    },
    // 对于保持keep-alive组件, 监听有没有进行切换
    // keep-alive组件进入活跃状态
    activated() {
      console.log("home activated")
    },
    deactivated() {
      console.log("home deactivated")
    }
  }
</script>

<style scoped>
</style>

 

标签:console,log,alive,keep,Home,home
From: https://www.cnblogs.com/qd-lbxx/p/16615092.html

相关文章

  • zookeeper总结
    zk是分布式协调服务。架构角色,分为leaderfollowerobserver。follower参与选举。observer提供读操作。特点:1、高可用,主从架构,官方测试主节点挂了,200ms完成恢复,也就是主......
  • 1022 Meeting(uvalive 可能会交不上) 分层图 最短路
    BessieandherfriendElsiedecidetohaveameeting.However,afterFarmerJohndecoratedhisfencestheywereseparatedintodifferentblocks.John’sfarma......
  • zookeeper:
     1.zk的主要作用:1.zk+dubbo注册数据的时候生产者和消费者节点下url为临时节点。其余如配置文件等节点都是持久节点。2.作为分布式锁中间件。3.分布式......
  • Keepalived lvs
    keepalived选举策略首先,每个节点有一个初始优先级,由配置文件中的priority配置项指定,MASTER节点的priority应比BAKCUP高。运行过程中keepalived根据vrrp_script......
  • 基于Zookeeper案例实现微服务动态注册和发现案例
    zookeeper+dubbo微服务架构 创建provider资源      创建dubboprovider生产者Dockerfileroot@deploy:/dockerfile/project/dubbo#catDockerfile#Dubbop......
  • nginx+keepalived 主备实现高可用
    nginx+keepalived主,当一台主机挂掉,由备用主机顶上主机:192.168.59.102:master192.168.59.103:backup 1、安装nginx(两台主机都安装)https://www.cnblogs.com/leihongnu/......
  • keepalived 虚拟ip可以切换(漂移),但无法通过虚拟ip访问(curl: (7) Failed connect to 192
    虚拟ip可切换  关闭192.168.59.102上的keepalived  但是访问超时:curl:(7)Failedconnectto192.168.59.211:8088;Connectiontimedout 修改MASTER路由和......
  • helm 部署kafka,zookeeper集群
    环境要求:k8s集群,helm组件实现:helmrepoaddbitnamihttps://charts.bitnami.com/bitnamihelmrepoupdatehelminstallkafkabitnami/kafka\ --setstatefulset.r......
  • Linux下搭建ZooKeeper集群并整合Dubbo配置
    1.环境说明Zookeeper不仅可以单机提供服务,同时也支持多机组成集群来提供服务,实际上Zookeeper还支持另外一种伪集群的方式,也就是可以在一台物理机上运行多个Zookeeper......
  • vue3 做keepalive需要注意的事项
    再vue2里面做可以这么写:<keep-alive><router-view></router-view></keep-alive>但是报一个警告:vue-router.mjs:35[VueRouterwarn]:<router-view>cann......