From b422242552880746d17b4f0f8e2ad9251f8fcd04 Mon Sep 17 00:00:00 2001 From: hshanx Date: Tue, 4 Aug 2020 21:36:46 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix:=20Fix=20comment=20origin=20?= =?UTF-8?q?html=20tag=20perform=20(halo-dev/console#222)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/util.js | 9 +++++++++ src/views/comment/components/CommentTab.vue | 4 +++- src/views/comment/components/TargetCommentTree.vue | 4 +++- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/utils/util.js b/src/utils/util.js index 7d131a350..90c6ac0ab 100644 --- a/src/utils/util.js +++ b/src/utils/util.js @@ -44,3 +44,12 @@ export function isObject(value) { export function datetimeFormat(value, pattern = 'YYYY-MM-DD HH:mm') { return moment(value).format(pattern) } + +// decode html tag +export function decodeHTML(html) { + let elem = document.createElement('div') + elem.innerHTML = html + const output = elem.innerText || elem.textContent + elem = null + return output +} diff --git a/src/views/comment/components/CommentTab.vue b/src/views/comment/components/CommentTab.vue index e56741458..50dd6f489 100644 --- a/src/views/comment/components/CommentTab.vue +++ b/src/views/comment/components/CommentTab.vue @@ -441,6 +441,8 @@ import { mixin, mixinDevice } from '@/utils/mixin.js' import CommentDetail from './CommentDetail' import marked from 'marked' import commentApi from '@/api/comment' +import { decodeHTML } from '@/utils/util' + const postColumns = [ { title: '昵称', @@ -576,7 +578,7 @@ export default { formattedComments() { return this.comments.map(comment => { comment.statusProperty = this.commentStatus[comment.status] - comment.content = marked(comment.content) + comment.content = marked(decodeHTML(comment.content)) return comment }) } diff --git a/src/views/comment/components/TargetCommentTree.vue b/src/views/comment/components/TargetCommentTree.vue index adb09d173..336760139 100644 --- a/src/views/comment/components/TargetCommentTree.vue +++ b/src/views/comment/components/TargetCommentTree.vue @@ -97,6 +97,8 @@