Home >Backend Development >PHP Tutorial >vue.js sets cookie instance sharing
Related recommendations:
This article mainly shares with you vue.js cookie setting examples. Hope it helps everyone.
//设置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(); }
Related recommendations:
Detailed explanation of the method instance of setting cookie in javascript
Detailed explanation of the HTTPONLY attribute method of setting Cookie in PHP
Server-side PHP sets cookies, but the client does not take effect
The above is the detailed content of vue.js sets cookie instance sharing. For more information, please follow other related articles on the PHP Chinese website!