1.4.2 • Published 3 years ago
ypf-methods v1.4.2
ypf-methods
使用方式
01. 安装此包
npm i ypf-methods
02. 在 main.js 中 引入
import ypfMethods form 'ypf-methods'
03. 绑定至原型链使用
vue 2.x -> Vue.prototype.$ypfMethods = ypfMethods
vue 3.x -> app.config.globalProperties.$ypfMethods = ypfMethods
方法说明:
1. _deepClone // 深拷贝
参数:字符串或引用类型
返回值:新的对象
深拷贝:改变对象或数组或字符串的地址
let obj = {
aa: undefined,
name: 'xm',
birth: new Date,
desc: null,
reg: /^123$/,
ss: [1,2,3],
fn: function() {
console.log('123')
},
}
let obj2 = _deepClone(obj)
//输出结果:
obj2: {
aa: undefined,
name: 'xm',
birth: new Date,
desc: null,
reg: /^123$/,
ss: [1,2,3],
fn: function() {
console.log('123')
},
}
2. _encryStr // 字符串加星号(*)展示
_encryStr(str, start, end)
参数:str:string 字符串,start:起始下标,end:结束下标(可以是负数,从末尾起始是 -1,以此类推)
返回值:返回带 \* 的字符串
let str = '15631171756'
_encryStr(str, 3, 7) // 156****1756
_encryStr(str, 3, -4) // 156****1756
3. _getUrlQuery // 获取地址栏上拼接的参数
_getUrlQuery(key)
参数:key: string 字符串
返回值:key 的 value 值
// 若当前地址栏 url = http://localhost:8080/detail/2784?code=123&name=yyy
_getUrlQuery('code') // 123
_getUrlQuery('name') // yyy
4. _moneyBigFormat // 金额转大写
_moneyBigFormat(val)
参数:val: string 字符串 或 number 的金额数字
返回值:大写的数字
_moneyBigFormat(123456.78) // 壹拾贰万叁仟肆佰伍拾陆元柒角捌分
_moneyBigFormat('123456.78') // 壹拾贰万叁仟肆佰伍拾陆元柒角捌分
5. _moneyReplace // 金额格式限制
适合于 input 输入框变化时的 input 事件
_moneyReplace(val)
参数:val: string 字符串 或 number 的金额数字
返回值:过滤之后的合法的金额字符串
_moneyReplace(9.1512) // 9.15
_moneyReplace('9.1512') // 9.15
_moneyReplace('a') // 0
6. _moneyThousandFormat // 金额添加千分符
_moneyThousandFormat(val)
参数:val: string 字符串 或 number 的金额数字
返回值:过滤之后的带千分符的金额字符串
_moneyThousandFormat(12345678) // 12,345,678.00
_moneyThousandFormat('123456.78') // 123,456.78
7. _CookieUtil // cookie 操作方法
_CookieUtil 是一个封装好操作方法的对象,内有 setCookie、getCookie、removeCookie 三个方法
(1)setCookie(key, val, timeStamp)
参数: key 键值, val 值, timeStamp 有效时长,时间戳格式(不传默认为当天23:59:59过期)
返回值:无返回值
_CookieUtil.setCookie('name', 'yyy', 1 * 24 * 60 * 60 * 1000)
(2)getCookie(key)
参数: key 键值
返回值:key 的 value 值
_CookieUtil.getCookie('name') // yyy
(3)removeCookie(key)
参数: key 键值
返回值:无返回值
_CookieUtil.getCookie('name')
1.4.2
3 years ago
1.4.1
3 years ago
1.4.0
3 years ago
1.3.18
3 years ago
1.3.19
3 years ago
1.3.20
3 years ago
1.3.21
3 years ago
1.3.14
3 years ago
1.3.17
3 years ago
1.3.15
3 years ago
1.3.13
3 years ago
1.3.12
3 years ago
1.3.10
3 years ago
1.3.11
3 years ago
1.3.9
3 years ago
1.3.7
3 years ago
1.3.6
3 years ago
1.3.5
3 years ago
1.3.8
3 years ago
1.2.5
4 years ago
1.2.4
4 years ago
1.2.3
4 years ago
1.2.2
4 years ago
1.2.1
4 years ago
1.2.0
4 years ago
1.1.1
4 years ago
1.1.0
4 years ago
1.1.7
4 years ago
1.1.6
4 years ago
1.0.7
4 years ago
1.1.5
4 years ago
1.1.4
4 years ago
1.1.3
4 years ago
1.1.2
4 years ago
1.0.6
4 years ago
1.0.5
4 years ago
1.0.4
4 years ago
1.0.3
4 years ago
1.0.2
4 years ago
1.0.1
4 years ago
1.0.0
4 years ago