限制输入字数

This commit is contained in:
binbin_pan 2024-04-22 12:04:29 +08:00
parent f175c44ba1
commit 3e1db1b125
1 changed files with 15 additions and 1 deletions

View File

@ -261,7 +261,7 @@
v-model="form.noticeContent"
:min-height="192"
:max-length="200"
:placeholder="'请输入内容'"
@input="handleEditorChange"
/>
</el-form-item>
</el-col>
@ -433,6 +433,20 @@
})
.catch(() => {})
},
handleEditorChange(value) {
let parser = new DOMParser()
let doc = parser.parseFromString(value, "text/html")
let text = doc.body.textContent || ""
// text.length 200 ,200
if (text.length > 200) {
this.$message({
message: '公告内容不能超过200个字符!',
type: 'warning'
})
this.form.noticeContent = text.substring(0, 200)
return
}
},
},
}
</script>