vue中文本域限制字數的方法


用watch方法,來限制字數

<template>
  <div class="box">
        <textarea  v-model="title" width="100%" ></textarea>
         <span>還可以輸入{{this.titleMaxLength - this.title.length}}</span>
  </div>
</template>
<script>
export default {
  name: 'Box',
    data() {
        return {
            title: '',
            titleMaxLength: 60
        };
    },
    methods:{
    },
    watch: {
        title() {
            if (this.title.length > this.titleMaxLength) {
                this.title = String(this.title).slice(0, this.titleMaxLength);
            }
        }
    }
}
</script>
<style lang="less">
.box{
    width: 100%;
    textarea{
        width: 100%;
        height: 60px;
        border: none;
        outline: none;
        box-sizing: border-box;
    }
}
</style>

  


免責聲明!

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



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