一、如果跳转的链接中有中文,复制时会自动转码,怎么解决这一问题?
传参
const name=encodeURIComponent(data.name)
接收参数
this.name = this.decodeURIComponentSafe(this.deleteNumber(this.$route.query.name))
// 解决qq浏览器,文件名解码失败 ,当时时临时想到的把内容转回去,百度一圈也不知道怎么办
deleteNumber(str) {
if (!str) return
return str.replaceAll('%25', '%').replaceAll('%3F', '?').replaceAll('%23', '#').replaceAll('%26', '&').replaceAll('%3D', '=')
},
//真正的转码
decodeURIComponentSafe(uri, mod) {
var out = new String(),
arr,
i = 0,
l,
x;
typeof mod === "undefined" ? mod = 0 : 0;
arr = uri && uri.split(/(%(?:d0|d1)%.{2})/);
for (l = arr.length; i < l; i++) {
try {
x = decodeURIComponent(arr[i]);
} catch (e) {
x = mod ? arr[i].replace(/%(?!\d+)/g, '%25') : arr[i];
}
out += x;
}
return out;
},