1👍
✅
This is how you can get it
<script setup>
import { ref, onMounted } from 'vue'
const cube = ref(null)
onMounted(() => {
console.log(cube.value.clientWidth)
})
</script>
<template>
<div ref="cube">nice</div>
</template>
<style scoped>
div {
width: 200px;
height: 300px;
background-color: orange;
}
</style>
Here is an example.
Regarding Vue’s lifecycle hooks, setup()
doesn’t have the element attached to the DOM yet, hence why you may not have anything regarding window-related properties of your object.
Source:stackexchange.com