Vue Autosize Directive (Vue 2)

1.0.2 · abandoned · verified Sun Apr 19

The `vue-autosize` package provides a simple Vue 2 directive that integrates the `autosize.js` library into Vue applications, allowing `textarea` elements to automatically adjust their height to fit content. While `autosize.js` itself is actively maintained (latest v6.0.1, published February 2023), this specific Vue 2 wrapper (v1.0.2) is not actively maintained and does not support Vue 3. For new projects or Vue 3, developers should consider modern alternatives like `v-autosize` (a Vue 3 wrapper), `vue-textarea-autosize` (a component-based solution), or `useTextareaAutosize` from VueUse. Its key differentiator was its straightforward directive-based approach for Vue 2, simplifying textarea resizing without complex component structures.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates global registration of the `v-autosize` directive and its application to `textarea` elements in a Vue 2 instance, showing automatic height adjustment.

import Vue from 'vue';
import VueAutosize from 'vue-autosize';

Vue.use(VueAutosize);

new Vue({
  el: '#app',
  data: {
    message: 'This textarea will automatically adjust its height as you type. Try typing a lot of text here to see it expand vertically. The underlying autosize.js library handles the resizing logic efficiently.',
    anotherMessage: 'Short message.'
  },
  template: `
    <div id="app">
      <h3>Autosizing Textareas</h3>
      <textarea v-autosize v-model="message" style="width: 100%; border: 1px solid #ccc; padding: 8px;"></textarea>
      <p>Current message length: {{ message.length }}</p>
      <br>
      <textarea v-autosize v-model="anotherMessage" style="width: 100%; border: 1px solid #ccc; padding: 8px;"></textarea>
    </div>
  `
});

view raw JSON →