Vue监听文本框实时输入限制输入长度

    技术2022-07-16  87

    <textarea v-model="value" placeholder="输入内容" @input="inputArea()"></textarea> new Vue({ el: ".box", data: { value: "", maxLength: 100, currentLength: 0 }, methods: { inputArea() { this.currentLength = this.value.length if (this.currentLength > this.maxLength) { this.currentLength = 100 this.value = this.value.slice(0, 100) } }, } })
    Processed: 0.016, SQL: 9