I'm trying to get width value from Template and pass the value to child component in vue/nuxt.
However, it doesn't work out. I assume that is because width from template is obtained later stage in life cycle hook.
How could I ensure the width value is obtained first and the child element gets the information?
Parent
<template>
<v-col cols="12" sm="12" md="4" ref="demandContainer">
<div class="chart-container p-4 dark-background">
<div class="font-weight-bold">Demand</div>
<area-chart
v-if="trendsData.length > 0"
:data="trendsData"
:baseWidth="width"
>
</area-chart>
</div>
</v-col>
</template>
<script>
export default {
updated() {
this.width = this.$refs.demandContainer.$el.clientWidth
},
}
</script>
Child
<svg ref="svg-area" :width="baseWidth" :height="baseHeight">
</svg>