遇到了一个element-ui为1.x版本的,输入框和文本域没有show-word-limit属性,手动加一个字数限制展示,可以配合maxlength使用
<el-form-item label="描述文字">
<el-input
maxlength="20"
type="textarea"
v-model="form.desc"
placeholder="请输入描述文字"
></el-input>
<span class="str-limit">{{descStrLimit}}/20</span>
</el-form-item>
data(){
return{
descStrLimit:0
}
}
watch: {
"form.desc": {
handler(val) {
this.descStrLimit= val.length;
},
immediate: true,
},
}
<style lang="scss" scoped>
.el-form-item {
.str-limit {
position: absolute;
right: 10px;
bottom: 5px;
line-height: 1;
color: #999;
}
}
</style>