@gyw123/utils
v1.0.4
Published
工具库
Downloads
3
Readme
axiosRequest
axios请求封装
- GET
import {get} from "@ninggure/utils/axiosRequest";
// 请求链接
const url = "http://xxxx.com";
// 参数
const params = {
a: 1
}
// 请求头, 可以不设置
const headers = {}
// 响应内容格式, 可以不设置,默认为json
const responseType = "json";
get(url, params, headers, responseType)
- POST
import {post} from "@ninggure/utils/axiosRequest";
// 请求链接
const url = "http://xxxx.com";
// 参数
const data = {
a: 1
}
// 请求头, 可以不设置
const headers = {}
// 响应内容格式, 可以不设置,默认为json
const responseType = "json";
post(url, params, headers, responseType)
- 上传文件(POST)
import {uploadFile} from "@ninggure/utils/axiosRequest";
// 请求链接
const url = "http://xxxx.com";
// 参数
const data = {
file
}
// 请求头, 可以不设置
const headers = {}
// 响应内容格式, 可以不设置,默认为json
const responseType = "json";
uploadFile(url, params, headers, responseType)
deepClone
深拷贝对象或数组
- depthDeepClone(深度遍历深拷贝)
import {depthDeepClone} from "@ninggure/utils/deepClone";
const a = {test: 1, test2: 2, test3: {
test: 1
}}
// 深拷贝一个a对象
const newA = depthDeepClone(a);
console.log(a === newA) // false
- breadthDeepClone(广度遍历深拷贝)
import {breadthDeepClone} from "@ninggure/utils/deepClone";
const a = {test: 1, test2: 2, test3: {
test: 1
}}
// 深拷贝一个a对象
const newA = breadthDeepClone(a);
console.log(a === newA) // false
fileList
遍历目录里面的所有内容
- getDepthFileList(深度遍历)
const {getDepthFileList} = require("@ninggure/utils/fileList");
const dirPath = "xxxx";
getDepthFileList(dirPath)
- getBreadthFileList(广度遍历)
const {getBreadthFileList} = require("@ninggure/utils/fileList");
const dirPath = "xxxx";
getBreadthFileList(dirPath)