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