refs使用

2021-10-26  本文已影响0人  iOS白水

1.页面生命周期

image.png

_mounted

image.png

所以 onshow 去使用 refs 有概率 会拿不到

  1. 解决方案
    包一层 nexttrick
image.png



 //
  onShow() {
    console.log('my_page_onShow');
    console.log('my_page_onShow_refs:', this.$refs.activityAd);
    this.$nextTick(() => {
      console.log('my_page_onShow_nextTick');
      console.log('my_page_onShow_nextTick_refs:', this.$refs.activityAd);
    });
  },
  onHide() {
    console.log('my_page_onHide');
    console.log('my_page_onHide_refs:', this.$refs.activityAd);
    this.$nextTick(() => {
      console.log('my_page_onHide_nextTick');
      console.log('my_page_onHide_nextTick_refs:', this.$refs.activityAd);
    });
  },
  created() {
    console.log('my_page_created');
    console.log('my_page_created_refs:', this.$refs.activityAd);
    this.$nextTick(() => {
      console.log('my_page_created_nextTick');
      console.log('my_page_created_nextTick_refs:', this.$refs.activityAd);
    });
  },
  mounted() {
    console.log('my_page_mounted');
    console.log('my_page_mounted_refs:', this.$refs.activityAd);
    this.$nextTick(() => {
      console.log('my_page_mounted_nextTick');
      console.log('my_page_mounted_nextTick_refs:', this.$refs.activityAd);
    });
  },

image.png
上一篇 下一篇

猜你喜欢

热点阅读