tips07-encodeURI()的使用

url中不能带有中文, 所有在url中拼接字符串的时候, 要先对中文进行编码

encodeURI() 函数可以把字符串作为uri编码

let cityName = encodeURI('武汉')

fetch(`http://v.juhe.cn/weather/index?&cityname=${cityName}`)

如果遇到以下报错 , 可能原因就是这个

TypeError: Request path contains unescaped characters(非转义字符)

原文地址:https://www.cnblogs.com/noraZhang/p/10273512.html