While I understand that in Vue we can access template refs to use getBoundingClientRect()
with the options API like this:
const rect = this.$refs.image.$el.getBoundingClientRect();
I am now attempting to achieve the same using template refs within the composition API in Vue as shown below:
const image = ref(null);
const rect = image.value.getBoundingClientRect();
This approach is functional, but it prompts an undesirable error message:
Object is possibly 'null'
I have also tried the following code, yet the error persists.
const rect = image?.value.getBoundingClientRect();