vue.js设置cookie实例分享
程序员文章站
2022-04-30 15:43:34
...
相关推荐:
本文主要和大家分享vue.js设置cookie实例分享。希望能帮助到大家。
//设置cookie<存>setCookie: function (cname, cvalue, exdays) { var d = new Date(); d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000)); var expires = "expires=" + d.toUTCString(); console.info(cname + "=" + '111' + "; " + expires); document.cookie = cname + "=" + cvalue + "; " + expires; },//获取cookiegetCookie: function (cname) { var arr, reg = new RegExp("(^| )" + cname + "=([^;]*)(;|$)"); if (arr = document.cookie.match(reg)) return (arr[2]); else return null; },
删除cookie
delCookie: function (name) {
var exp = new Date(); exp.setTime(exp.getTime() - 1); var cval = getCookie(name); if (cval != null) document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString(); }
相关推荐:
以上就是vue.js设置cookie实例分享的详细内容,更多请关注其它相关文章!