一、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可以使用組件自帶的方法。)