[Vuejs]-How to get _value properties in Vue 3 ref

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.

enter image description here


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.

👤kissu

Leave a comment