htmlEncode htmlDecode

发布时间 2023-11-09 09:43:42作者: itjeff

htmlEncode htmlDecode
v-html: 如果是富文本,直接导入;如果不是富文本,需要htmlEncode再导入

htmlEncode : function(value){
  return !value ? value : String(value).replace(/&/g, "&amp;").replace(/>/g, "&gt;").replace(/</g, "&lt;").replace(/"/g, "&quot;");
},


htmlDecode : function(value){
  return !value ? value : String(value).replace(/&gt;/g, ">").replace(/&lt;/g, "<").replace(/&quot;/g, '"').replace(/&amp;/g, "&");
},

原文链接:https://blog.csdn.net/x_duoduoluo/article/details/128931321