实例 Vue deactivated 生命周期钩子实例

x
 
<template>
  <h1>The 'deactivated' Lifecycle Hook</h1>
  <p>Using the 'deactivated' hook to log when the 'deactivated' hook is called.</p>
  <button @click="this.activeComp = !this.activeComp">Include component</button>
  <div>
    <KeepAlive>
      <comp-one v-if="activeComp"></comp-one>
    </KeepAlive>
  </div>
</template>
<script>
export default {
  data() {
    return {
      activeComp: false
    }
  }
}
</script>
<style scoped>
  div {
    border: dashed black 1px;
    border-radius: 10px;
    padding: 20px;
    margin-top: 10px;
    background-color: lightgreen;
  }
</style>                  

输出结果