URL.toJSON

最近更新时间:2023-05-17 10:10:18

我的收藏
URL.toJSON 用于获取序列化的网址,当 URL 对象用 JSON.stringify() 序列化时,会自动调用此方法。
toJSON(): string

返回

类型
描述
string
序列化的网址

样例

import url from 'pts/url';

export default function () {
const u = 'http://user:pass@www.example.com:8080/test/index.html?name=xxx&age=18#worker';

const uu = new url.URL(u);
console.log(uu.toJSON()); // http://user:pass@www.example.com:8080/test/index.html?name=xxx&age=18#worker
}