0.1.1 • Published 5 years ago

lxxfun v0.1.1

Weekly downloads
5
License
ISC
Repository
-
Last release
5 years ago

JavaScript常用函数方法封装

代码运行

yarn install || npm i

yarn start || npm start

方法说明

ajax (接口请求封装)

使用说明:
依赖于axios、qs插件
入参说明[get, post, delete, put]:
1、URL
2、params 参数
3、axios 参数合并 [深度合并]
this.ajax = new lxxFun.ajax({
    base : 'http://127.0.0.1:8089'
});

// 第一种使用方式
this.ajax.get('/test', {id : '1'}, {headers : {token : '123Token'}})
    .then(res => {
        // res 中包含请求头等信息 data 为接口真实数据
        console.log(res.data)
    })
    .catch(err => {
        console.error('发生错误:', err);
    });

// 第二种使用方式
let res = await this.ajax.get('/test', {id : '1'}, {headers : {token : '123Token'}});
console.log(res.data);

deepClone (数据深copy)

使用说明:
类型支持:
null undefined 
number string
array object

入参说明:
1、需要深拷贝的数据

出参说明:
1、若入参数据 为 null undefined 会 return 对应的参数(不会随数据而改变)
2、若入参数据 为 number string 会使用 JSON.parse(JSON.stringify(data)) 进行深拷贝
3、若入参数据 为不支持的类型 会返回一个空 object
let data = ['1', '2']; 
let a = lxxFun.deepClone(data);
data = ['2', '3'];
console.log(a);

getUuid (16进制UUID)

使用说明:
出参:
1、string
let uuid = lxxFun.getUuid();
console.log(uuid)