node.js中的url.format方法使用说明
2023-06-13 09:15:32 时间
方法说明:
将一个解析后的URL对象、转成、一个格式化的URL字符串。
语法:
url.format(urlObj)
接收参数:
urlObj表示URL对象,可包含以下属性:(可对照例子)
href 完整路径
protocolis 协议(如http://)
auth
hostname 主机名
port 端口
host 主机(主机名+端口)
pathname ‘/"可以理解成目录
query 参数列表
search 查询条件(就是加上“?”的参数列表)
hash 哈希值
例子:
varurl=require("url");
vara=url.format({
protocol:"http",
auth:null,
host:"example.com:8080",
port:"8080",
hostname:"example.com",
hash:null,
search:"?a=index&t=article&m=default",
query:"a=index&t=article&m=default",
pathname:"/one",
path:"/one?a=index&t=article&m=default",
href:"http://example.com:8080/one?a=index&t=article&m=default"
});
console.log(a);
//输出结果:http://example.com:8080/one?a=index&t=article&m=default
相关文章
- 【说站】js中for...in语句的使用注意
- js中四舍五入的方法_JS取整
- js格式化CSS样式代码的方法
- js中几个记不住的方法详解编程语言
- JS产生四位随机数的方法详解编程语言
- js取整数、取余数的方法详解编程语言
- JS indexOf()和lastIndexOf()方法:在数组中查找某个元素
- jquery全选/全不选/反选另一种实现方法(配合原生js)
- flash调用js中的方法,让js传递变量给flash的办法及思路
- JS操作Array数组的方法及属性实例解析
- js获取和设置属性的方法
- js防止DIV布局滚动时闪动的解决方法
- node.js中的events.emitter.listeners方法使用说明
- node.js中的events.emitter.removeListener方法使用说明
- node.js中的buffer.slice方法使用说明
- node.js中的fs.writeFile方法使用说明
- node.js中的fs.write方法使用说明
- node.js中的fs.rmdirSync方法使用说明
- node.js中的fs.readSync方法使用说明
- node.js中的fs.futimes方法使用说明
- node.js中的fs.createReadStream方法使用说明
- js计算任意值之间随机数的方法