相关推荐:
本文主要和大家分享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; },
<br>
删除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实例分享的详细内容。更多信息请关注PHP中文网其他相关文章!