一:场景---参数中有%等,后端不方便处理,可以在前端传入时编辑(1)方法:encodeKey=key=>{constencodeArr=[{code:'%',encode:'%25',},{code:'?',encode:'%3F',},{code:'#',encode:'%23',},{code:'&',编码:'%26',},{代码:'=',编码:'%3D',},{代码:'+',编码:'%2B',},{代码:'/',编码:'%2F',},];returnkey.replace(/[%?#&=+/]/g,$=>{for(constkofencodeArr){if(k.code===$){returnk.encode;}}});};(2)调用this.encodeKey(key)如果封装到通用逻辑示例util.js页面,调用util.encodeKey(key)2:接口输出参数时返回不可转换的\n换行符(1)方法unEscapeHtml=content=>{letct=content;if(!ct)return'';constreg=/\\n/;if(reg.test(ct)){ct=ct.replace(/\\n/g,'');}constdiv=document.createElement('div');div.style.display='none';div.innerHTML=ct;returndiv.innerText;},};(2)调用这个。如果把unEscapeHtml(content)封装成通用逻辑例子util.js页面调用util.unEscapeHtml(content)三:输出参数时返回HTML实体&、<、>、"、'、`(1)方法页面importlodashfrom'lodash';调用:lodash.unescape(val)方法详解:https://www.lodashjs.com/docs...
