Skip to content

bug: vue, elements not shown at the moment did enter lifecycle is fired #24434

@honghuangdc

Description

@honghuangdc

Prerequisites

Ionic Framework Version

  • v4.x
  • v5.x
  • v6.x

Current Behavior

create a reference in dom, which is inside Icon-vue component, then get the config "offsetHeight", "offsetWidth", "clientHeight", "clientWidth" of the dom in lifecycle onMouted, but their value are all zero, and when I add setTimeout function to get config, it will get real value.

Expected Behavior

it can get the real value of config "offsetHeight", "offsetWidth", "clientHeight", "clientWidth" of the dom reference in lifecycle onMouted.

Steps to Reproduce

  1. set dom reference inside ionic-vue component
  2. in lifecycle onMouted, get the config "offsetHeight", "offsetWidth", "clientHeight", "clientWidth" value

here is the code:

<template>
  <ion-page>
    <div ref="domRef">dom test</div>
  </ion-page>
</template>

<script lang="ts">
import { defineComponent, ref, onMounted } from 'vue';
import { IonPage } from '@ionic/vue';

export default defineComponent({
  name: 'App',
  components: {
    IonPage
  },
  setup() {
    const domRef = ref<HTMLElement | null>(null)

    onMounted(() => {
      console.log(domRef.value) // it can get dom reference
      console.log(domRef.value?.offsetHeight) // but the value is zero
      console.log(domRef.value?.offsetWidth)
      console.log(domRef.value?.clientHeight)
      console.log(domRef.value?.clientWidth)
    })

    return {
      domRef
    }
  }
});
</script>
<style scoped></style>

Code Reproduction URL

No response

Ionic Info

No response

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions