• vue-cookies


    安装vue-cookies

    npm install vue-cookies --save

    引入vue-cookies

    import Vue from 'vue'
    import VueCookies from 'vue-cookies'
    Vue.use(VueCookies)

    API

    -设置全局配置,设置cookie过期时间和url

    this.$cookies.config(expireTimes[,path])  // default: expireTimes = 1d , path=/

    -设置一个cookie

    this.$cookies.set(keyName, value[, expireTimes[, path[, domain[, secure]]]])   //return this

    -获取一个cookie 

    this.$cookies.get(keyName)       // return value   

    -删除一个cookie

    this.$cookies.remove(keyName [, path [, domain]])   // return this

    -检查某个 cookie name是否存在

    this.$cookies.isKey(keyName)        // return false or true

    -获取所有 cookie name,以数组形式返回

    this.$cookies.keys()  // return a array

    设置cookie过期时间

    全局设置
    // 30天后过期
    this.$cookies.config('30d')
    
    this.$cookies.config(new Date(2019,03,13).toUTCString())
    
    this.$cookies.config(60 * 60 * 24 * 30,'');
    
    // window object
    window.$cookies.config('30d')
    单个name设置
    //不写过期时间,默认为1天过期
    this.$cookies.set("user_session","25j_7Sl6xDq2Kc3ym0fmrSSk2xV2XkUkX")
    
    // 1天过期,忽略大小写
    this.$cookies.set("user_session","25j_7Sl6xDq2Kc3ym0fmrSSk2xV2XkUkX","1d")
    this.$cookies.set("user_session","25j_7Sl6xDq2Kc3ym0fmrSSk2xV2XkUkX","1D")
    
    // 以秒为单位,设置1天过去
    this.$cookies.set("user_session","25j_7Sl6xDq2Kc3ym0fmrSSk2xV2XkUkX",60 * 60 * 24)
    
    // 填写Date对象,明确指定过期时间
    this.$cookies.set("user_session","25j_7Sl6xDq2Kc3ym0fmrSSk2xV2XkUkX", new Date(2017, 03, 12))
    
    // 填写一个时间字符串,指定过期时间
    this.$cookies.set("user_session","25j_7Sl6xDq2Kc3ym0fmrSSk2xV2XkUkX", "Sat, 13 Mar 2017 12:25:57 GMT")
    
    //浏览器会话结束时过期
    this.$cookies.set("default_unit_second","input_value","0");
     
    //永不过期
    this.$cookies.set("default_unit_second","input_value",-1); 
    字符串单位形式设置

    设置过期时间,输入字符串类型(字符均忽略大小写):

    this.$cookies.set("token","GH1.1.1689020474.1484362313","60s");  // 60秒后过去
    
    this.$cookies.set("token","GH1.1.1689020474.1484362313","30MIN");  // 30分钟后过去
    
    this.$cookies.set("token","GH1.1.1689020474.1484362313","24d");  // 24天后过期
    
    this.$cookies.set("token","GH1.1.1689020474.1484362313","4m");  // 4个月后过期
    
    this.$cookies.set("token","GH1.1.1689020474.1484362313","16h");  // 16小时后过期
    
    this.$cookies.set("token","GH1.1.1689020474.1484362313","3y");  // 3年后过期
     
     
     
    幻想毫无价值,计划渺如尘埃,目标不可能达到。这一切的一切毫无意义——除非我们付诸行动。
  • 相关阅读:
    搭建MHA问题汇总
    NOIP2009 靶形数独
    get_mysql_conn_info.py
    NOIP 2005 篝火晚会
    MySQL启动关闭添加到 /etc/init.d/mysqld
    noip2002 矩形覆盖
    get_slave_status.py
    [JSOI2008]魔兽地图
    MySQL数据导出导入任务脚本
    8.30 牛客OI赛制测试赛1 F题 子序列
  • 原文地址:https://www.cnblogs.com/TodayWind/p/13972495.html
Copyright © 2020-2023  润新知