码迷,mamicode.com
首页 > Web开发 > 详细

util.js

时间:2019-01-02 01:29:05      阅读:264      评论:0      收藏:0      [点我收藏+]

标签:++   获取   cti   ring   value   get   ons   val   sea   

1.获取URL search参数

import qs from ‘qs‘

export default function getQueryParam(param) {
    let { search } = window.location;

    search = search.slice(1);

    const params = qs.parse(search);

    if (param) {
        return Object.prototype.hasOwnProperty.call(paramss, param)
            ? params[param]
            : null;
    }

    return params;
}
  1. 只返回obj中满足fn(key, value) === true的key, value的对象
export function pick(obj, fn = (key, value) => !!value || value === 0) {
    const ret = {};
    
    if (obj) {
        Object.keys[obj].forEach(key => {
            if (fn(key, obj[key])) {
                ret[key] = obj[key];
            }
        });
    }
    return ret;
}
  1. 获取cookie和cToken
export function getCookie(cookieName) {
    const name  = `${cookieName}=`;
    const cookies = document.cookie.split(‘;‘);

    for (let i = 0; i < cookies.length; i++) {
        const cookie  = cookies[i].trim();
        if (cookie.indexOf(name) === 0) {
            return cookie.substring(name.length, cookie.length);
        }
    }
    return ‘‘;
}

export function getCToken(){
    return getCookie(‘ctoken‘);
}

util.js

标签:++   获取   cti   ring   value   get   ons   val   sea   

原文地址:https://www.cnblogs.com/lei--lei/p/10206554.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!