URI.js
URI.js是一個用於處理URL的JavaScript庫
它提供了一個“jQuery風格”的API(Fluent接口,方法鏈接)來讀寫所有常規組件和許多便利方法,如.directory()和.authority()
本文以URI.js庫為例進行講解
鏈接:
http://medialize.github.io/URI.js/
https://github.com/medialize/URI.js
ts使用js
安裝URI.js
npm install urijs
配置tsconfig.json
{
"compilerOptions": { // 允許調用js "allowJs": true } }
使用js
import * as URL from 'urijs' // get請求 getRequest(url: string, params: any): Promise<any> { //... //把any轉為key=value&key=value... url=url+'?'+URL.buildQuery(params); //... }