Home > Backend Development > PHP Tutorial > vue.js sets cookie instance sharing

vue.js sets cookie instance sharing

小云云
Release: 2023-03-21 08:18:01
Original
1881 people have browsed it

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 + "=" + &#39;111&#39; + "; " + 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;

},
Copy after login
<br/>
Copy after login
删除cookie
Copy after login
delCookie: function (name) {
Copy after login
    var exp = new Date();
    exp.setTime(exp.getTime() - 1);    var cval = getCookie(name);    if (cval != null)
        document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString();
}
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template