<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="Width = device - width, initial - scale = 1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Encapsulate the cookie</title>
</head>
<body>
    
</body>
<script src="./cookie.js"></script>
<script>
    const {cookie}= cookies; // To introduce a declaration
    cookie.set('maomin'.'22'.'0.5');
    console.log(cookie.get("maomin"));
</script>
</html>
Copy the code

cookie.js

const cookies = {
    cookie: {
    / / set the cookie
        set: (name, value, day) = > {
            const date = new Date(a); date.setDate(date.getDate() + day);document.cookie = name + "=" + value + "; expires=" + date;
        },
    / / get a cookie
        get: (key) = > {
            var arr = document.cookie.split("; ");
            for (var i = 0; i < arr.length; i++) {
                var arr1 = arr[i].split("=");
                if (arr1[0] == key) {
                    return arr1[1]}}return ""
        },
     / / delete the cookie
        remove: (name) = > {
            cookie.set(name,' '.- 1)}}}Copy the code