vue 限制輸入字符長度


一、watch方法:

<input v-model="textareaValue" type="textarea"  placeholder="請輸入。。。" style="width:100%; height:100px;">
<p>還可以輸入<span>{{10 - textareaValue.length}}</span>個字符</p>
watch: {
  textareaValue(curVal, oldVal) {
    if (curVal.length > this.titleMaxLength) {
      this.textareaValue = String(curVal).slice(0, this.titleMaxLength);
    }
  }
}

(我嘗試使用iview-UI的input組件使用這個方法限制字符,存在問題。iview-UI可以使用組件自帶的方法。)


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM