NodeJs 中的 URL 编码字符串

Jom*_*ejo 1 php node.js

在 PHP 中我们有:

echo '<a href="mycgi?foo=', urlencode($userinput), '">';
Run Code Online (Sandbox Code Playgroud)

NodeJs 版本是什么urlencode();

小智 6

是你需要的吗? 网址编码

在这种情况下,可能与nodejs无关,在客户端仅使用javacript函数encodeURIComponent进行编码

例如:

var apiUrl: string = 'mycgi?foo=';
apiUrl += encodeURIComponent(userInput) 
Run Code Online (Sandbox Code Playgroud)