相關推薦:
本文主要和大家分享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(); }
相關推薦:
###服務端PHP設定cookie,客戶端未生效######以上是vue.js設定cookie實例分享的詳細內容。更多資訊請關注PHP中文網其他相關文章!