官方API地址:https://nodejs.org/api/url.html

url.parse():将url字符串转换为url对象

url.format():将url对象格式化为url 字符串

url.resolve():用于解析,接受两个参数,拼接

在node环境下直接输url,如下图

Node.js中url的parse、format、resolve方法详解

url.parse('http://imooc.com/course/list')

Node.js中url的parse、format、resolve方法详解

url.parse('http://imooc.com:8080/course/list?from=scott&course=node#floor1')

Node.js中url的parse、format、resolve方法详解

url.format(obj)

Node.js中url的parse、format、resolve方法详解

url.resolve();

Node.js中url的parse、format、resolve方法详解

url.parse('http://imooc.com:8010/course/list?from=scott&course=node#floor1',true):

第二个参数为true, query被转换为了一个对象

Node.js中url的parse、format、resolve方法详解

url.parse('//imooc.com/course/list',true,true);第三个参数为true,

第一个参数没有写http,不知道是http还是https协议

Node.js中url的parse、format、resolve方法详解

Node.js中url的parse、format、resolve方法详解

 

 

 

Node.js中url的parse、format、resolve方法详解

 

Node.js中url的parse、format、resolve方法详解

相关文章: