mm-base
v0.0.5
Published
前端基础库
Downloads
18
Keywords
Readme
mm-base
前端工具库
使用说明
安装
yarn add mm-base
Service 接口请求
import { Service } from 'mm-base'
class Http extends Service {
hanlderError(err: any): any {
return Promise.reject(err)
}
hanlderRequest(config: any): any {
return config
}
hanlderSuccess(response: any): any {
return Promise.resolve(response)
}
}
const api = new (new Api extends Http{
constructor() {
super('/api')
}
demo() {
return this.get('/get')
}
})
api.demo().then().catch()
storage 储存
import { storage } from 'mm-base'
// 设置本地储存
storage.local.set('key1', { info: 'value1' }, 10 * 60 * 1000 /*10分钟有效期*/)
// 获取本地储存
storage.local.get('key1')
// 设置会话储存
storage.session.set('key2', { info: 'value2' }, 10 * 60 * 1000 /*10分钟有效期*/)
// 获取会话储存
storage.session.get('key2')
time 时间
time 包含了一些常用时间常量,单位为毫秒
import { time } from 'mm-base'
// 1秒钟 1000
time.oneSecond
// 1分钟 60*1000
time.oneMinute
// 1小时 60*60*1000
time.oneHour
// 1天 24*60*60*1000
time.oneDay
// 1周 7*24*60*60*1000
time.oneWeek
// 1个月 30*24*60*60*1000
time.oneMonth
// 1年 365*24*60*60*1000
time.oneYear
// 1世纪 100*365*24*60*60*1000
time.oneCentury
// 永久(100世纪) 100*100*365*24*60*60*1000
time.forever
echo 输出
import { echo } from 'mm-base'
// 关闭echo.log输出
echo.isLog = false
// 输出一个信息
echo.log('this is message')
// 输出一个信息并报错
echo.error('this is message with error')
die 终止
import { die } from 'mm-base'
// 终止代码运行并给出提示信息
die.hint('error message')
第三方库
包含以下第三方库
// 获取 dayjs 对象,dayjs的使用详见 https://day.js.org/zh-CN
import { dayjs } from 'mm-base'
// 获取 lodash-es 对象,按需引入.lodash的使用详见 https://lodash.com
import { once } from 'mm-base'