zoukankan      html  css  js  c++  java
  • node.js的url解析和生成

    1.url的解析,用url.parse(urlStr)

    var url = 'localhost:8080/#/test'
    var urlModel = require('url')
    console.log(urlModel.parse(url));

    打印结果:

    Url {
      protocol: 'localhost:',
      slashes: null,
      auth: null,
      host: '8080',
      port: null,
      hostname: '8080',
      hash: '#/test',
      search: null,
      query: null,
      pathname: '/',
      path: '/',
      href: 'localhost:8080/#/test'
    }

    2.url生成,url.format(obj)

    var obj = {
        protocol: 'localhost:',
        slashes: null,
        auth: null,
        host: '8080',
        port: null,
        hostname: '8080',
        hash: '#/test',
        search: null,
        query: null,
        pathname: '/',
        path: '/',
        href: 'localhost:8080/#/test'
    }
    
    console.log(urlModel.format(obj));

    打印结果:

    localhost:8080/#/test
  • 相关阅读:
    P3413 SAC#1
    [BJOI2017]树的难题
    [HNOI/AHOI2018]转盘
    P2664 树上游戏
    [POI2013]BAJ-Bytecomputer
    [ZJOI2010]网络扩容
    数列游戏
    士兵占领
    [ZJOI2016]大森林
    P4755 Beautiful Pair
  • 原文地址:https://www.cnblogs.com/luguankun/p/12667661.html
Copyright © 2011-2022 走看看