一:场景---参数中有%等,后端不便解决可在前端传入时编辑
(1)办法:
encodeKey = key => {
const encodeArr = [ { code: '%', encode: '%25', }, { code: '?', encode: '%3F', }, { code: '#', encode: '%23', }, { code: '&', encode: '%26', }, { code: '=', encode: '%3D', }, { code: '+', encode: '%2B', }, { code: '/', encode: '%2F', },];return key.replace(/[%?#&=+/]/g, $ => { for (const k of encodeArr) { if (k.code === $) { return k.encode; } }});
};
(2)调用
this.encodeKey(key)
若封装到通用逻辑例util.js页面 调用util.encodeKey(key)
二:出参时接口返回不可转化的\n换行符
(1)办法
unEscapeHtml= content => {
let ct = content;if (!ct) return '';const reg = /\\n/;if (reg.test(ct)) { ct = ct.replace(/\\n/g, '');}const div = document.createElement('div');div.style.display = 'none';div.innerHTML = ct;return div.innerText;
},
};
(2)调用
this.unEscapeHtml(content)
若封装到通用逻辑例util.js页面 调用util.unEscapeHtml(content)
三:出参时返回 HTML 实体 &, <, >, ", ', 和 `
(1)办法
页面 import lodash from 'lodash'; 调用:lodash.unescape(val)
办法详解:https://www.lodashjs.com/docs...