Home  >  Article  >  Backend Development  >  vue.js sets cookie instance sharing

vue.js sets cookie instance sharing

小云云
小云云Original
2018-03-10 15:05:021827browse

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;

},
<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!

Statement:
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