首页 > Web开发 > 详细

3.node的url属性

时间:2017-11-21 21:29:43      阅读:212      评论:0      收藏:0      [点我收藏+]

node的url属性

1.parse: [Function: urlParse],
2.format: [Function: urlFormat],
3.resolve: [Function: urlResolve],
4.resolveObject: [Function: urlResolveObject],
5.URL: [Function: URL],
6.URLSearchParams: [Function: URLSearchParams],
7.domainToASCII: [Function: domainToASCII],
8.domainToUnicode: [Function: domainToUnicode]

 

 

一.cmd命令行输入"node", 进入node执行环境

1.parse: [Function: urlParse]

解析url地址, 第二个参数为true, 解析的query为成为对象模式
url.parse("http://www.imooc.com/video/6710" , true)
Url {
    protocol: ‘http:‘,
    slashes: true,
    auth: null,
    host: ‘www.imooc.com‘,
    port: null,
    hostname: ‘www.imooc.com‘,
    hash: null,
    search: ‘‘,
    query: {},
    pathname: ‘/video/6710‘,
    path: ‘/video/6710‘,
    href: ‘http://www.imooc.com/video/6710‘ 
}

第二个参数为true, 解析的query为成为对象模式
query: {form: "scott", "course" : "node"}

2.format: [Function: urlFormat]

还原url地址
url.format({
    protocol: ‘http:‘,
    slashes: true,
    auth: null,
    host: ‘www.imooc.com‘,
    port: null,
    hostname: ‘www.imooc.com‘,
    hash: null,
    search: null,
    query: null,
    pathname: ‘/video/6710‘,
    path: ‘/video/6710‘,
    href: ‘http://www.imooc.com/video/6710‘ 
})

3.resolve: [Function: urlResolve]

拼接成合法属性
url.resolve("http://www.imooc.com/", "/video/6710");
‘http://www.imooc.com/video/6710‘

技术分享图片 

3.node的url属性

原文:http://www.cnblogs.com/alantao/p/7875309.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!