美文网首页
refs使用

refs使用

作者: iOS白水 | 来源:发表于2021-10-26 15:13 被阅读0次

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

相关文章

网友评论

      本文标题:refs使用

      本文链接:https://www.haomeiwen.com/subject/bafviltx.html