1234567891011121314151617181920212223242526272829303132333435363738394041 |
- /**
- * 获取cookie
- * @param name
- * @returns {string|null}
- */
- function getCookie(name) {
- var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
- if (arr = document.cookie.match(reg))
- return (arr[2]);
- else
- return null;
- }
- /**
- * 设置cookie
- * @param c_name
- * @param value
- * @param expiredays
- */
- function setCookie (c_name, value, expiredays) {
- var exdate = new Date();
- exdate.setDate(exdate.getDate() + expiredays);
- document.cookie = c_name + "=" + escape(value) + ((expiredays == null) ? "" : ";expires=" + exdate.toGMTString());
- };
- /**
- * 删除cookie
- * @param name
- */
- function delCookie (name) {
- var exp = new Date();
- exp.setTime(exp.getTime() - 1);
- var cval = getCookie(name);
- if (cval != null)
- document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString();
- };
- export default {
- getCookie : getCookie,
- setCookie : setCookie,
- delCookie : delCookie
- }
|