300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > VUE --- 将HTML格式转换为纯文本

VUE --- 将HTML格式转换为纯文本

时间:2023-05-10 21:42:00

相关推荐

VUE --- 将HTML格式转换为纯文本

html代码:

<div>{{ToText(item.input)}}</div>

js代码:

methods:{ToText(HTML){var input = HTML;return input.replace(/<(style|script|iframe)[^>]*?>[\s\S]+?<\/\1\s*>/gi,'').replace(/<[^>]+?>/g,'').replace(/\s+/g,' ').replace(/ /g,' ').replace(/>/g,' '); }}

或 举例:

this.editorText = this.editor.txt.html()var a = this.editorText.replace(/<(style|script|iframe)[^>]*?>[\s\S]+?<\/\1\s*>/gi,'').replace(/<[^>]+?>/g,'').replace(/\s+/g,' ').replace(/ /g,' ').replace(/>/g,' ');if (a.length > 200) {this.$message.error('推广产品描述最多输入200个字符')return false}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。