html转义代码,v-html 显示原始html字符串
methods:
htmlEscape(str) {
htmlEscape(str) {
let s = "";
if (str.length == 0) return "";
s = str.replace(/&/g, "&");
s = s.replace(/</g, "<");
s = s.replace(/>/g, ">");
s = s.replace(/ /g, " ");
s = s.replace(/\'/g, "'");
s = s.replace(/\"/g, """);
return s;
}
调用:
let htmlStr = "<a href='http://www.baidu.com'>前往百度</a>"
this.htmlEscape(htmlStr )