mpvue应用之组件数据缓存清理

main.ts

Vue.mixin({
  // 监听页面加载
  onLoad() {
    this.componentShow = true;
  },
  // 监听页面卸载
  onUnload() {
    if (!this.$options.parent && this.$options.data) {
      this.componentShow = false;
      Object.assign(this.$data, this.$options.data());
    }
  },
});

页面中调用:

<script lang="ts">
  private componentShow: boolean = false;
</script>

<Popup v-if="componentShow" 
title="仓库记录" 
:show="recordShow" 
:content="buildingRecord" 
@cancel="popupShow('recordShow')" 
@confirm="recordConfirm"
 />

 

参考链接:https://zhuanlan.zhihu.com/p/50759400

 

posted @ 2020-07-07 16:38  放飞的回忆  阅读(273)  评论(0编辑  收藏  举报