electron-vue 设置cookie

//设置登录cookie
      setCookie(name,value){
        var Days=30;
        var exp=new Date();
        var date=Math.round(exp.getTime()/1000)+Days*24*60*60;
        const cookie = {
          url: this.webApi,
          name: name,
          value: value,
          expirationDate: date
        };
        session.defaultSession.cookies.set(cookie, (error) => {
          if (error) console.error(error);
        });
      },
      //清楚缓存
      cleanCookie(){
        session.defaultSession.clearStorageData({
          origin: this.webApi,
          storages: ['cookies']
        }, function (error) {
          if (error) console.error(error);
        })
      },
//获取cookies
       session.defaultSession.cookies.get({ url: this.webApi }, function (error, cookies) {
          console.log(cookies);
          if (cookies.length > 0) {
            _this.logText = cookies[0].value;
            if(cookies.length>1)
            {
              _this.pwdText = cookies[1].value;
              _this.checkState=true;       
              $(".layui-unselect").addClass("layui-form-checked"); 
            }
          }
        });

 

posted @ 2019-02-19 13:44  _小马哥  阅读(4484)  评论(3编辑  收藏  举报