In my Vue project, I am fetching a JSON array from an API and displaying its content in a list of textareas using v-for.
Whenever a user focuses on a textarea or edits the text within it, I want the textarea to automatically resize to fit the content.
<div v-for="post in posts">
<textarea v-model="post.body" rows="1" @focus="resizeTextarea" @keyup="resizeTextarea"></textarea>
</div>
resizeTextarea(e) {
let area = e.target;
area.style.overflow = 'hidden';
area.style.height = area.scrollHeight + 'px';
}
Despite my limited knowledge of Vue, I have been struggling to find a way to automatically resize all textareas after loading data from the API since there is no @load event for textareas.
I attempted to achieve this by using a watcher on the data, but it seems like a lengthy workaround.
Does anyone have a more efficient solution? Thank you!