因为我是elementui b表单里面,根据这个判断,我写在了,form的校验正则里面,所以就觉得效果还可以。没有更好的办法,有的话,请说。
watch: {
value: function (val) { // val是实时监测的输入值
if (!this.hasChange && this.hasInit) {
this.$nextTick(function () {
window.tinymce.get(this.id).setContent(val);
});
}
var str = window.tinymce.activeEditor.getContent();
var num = this.removeHTMLTag(str);
if (num.length > 3000) {
// 字符超出显示提示请重新修改后提交
}
}
removeHTMLTag: function (str) {
str = str.replace(/<\/?[^>]*>/g, '');
str = str.replace(/[ | ]*\n/g, '\n');
str = str.replace(/ /ig, '');
str = str.replace(/\s/g, '');
return str;
}
},