VUE使用cookie

作者: weisen | 来源:发表于2018-11-13 14:28 被阅读43次

文章参考:https://blog.csdn.net/qq_35573326/article/details/82049654

首先执行 :

npm install vue-cookies --save

在main.js全局引用

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

Api

  • Set a cookie
this.$cookies.set(keyName, value[, expireTimes[, path[, domain[, secure]]]])   //return this
  • Get a cookie
this.$cookies.get(keyName)       // return value                             
  • Remove a cookie
this.$cookies.remove(keyName [, path [, domain]])   // return  false or true , warning: next version return this; use isKey(keyname) return true/false,please
  • Exist a cookie name
this.$cookies.isKey(keyName)        // return false or true
  • Get All cookie name
this.$cookies.keys()  // return a array

例子

Support chaining sets together

 // default expire time: 1 day
this.$cookies.set("user_session","25j_7Sl6xDq2Kc3ym0fmrSSk2xV2XkUkX")    
        // Base of second
        .set("user_session","25j_7Sl6xDq2Kc3ym0fmrSSk2xV2XkUkX",60 * 60 * 24)

// check a cookie exist
this.$cookies.isKey("token")
// get a cookie
this.$cookies.get("token");
// remove a cookie
this.$cookies.remove("token");
// get all cookie key names, line shows
this.$cookies.keys().join("\n"); 
// vue-cookies global
[this | Vue | window].$cookies.[method] 

Warning

$cookies key names Cannot be set to ['expires','max-age','path','domain','secure']

相关文章

  • vue 中 直接操作 cookie 及 如何使用工具 js-co

    vue 中直接操作 cookie 以下3种操作方式 使用 js-cookie 工具:(比较方便,推荐使用) 工具地...

  • cookie跨域问题

    场景: springboot+shiro+vue shiro框架使用cookie做验证令牌 vue项目请求路径: ...

  • VUE使用cookie

    文章参考:https://blog.csdn.net/qq_35573326/article/details/82...

  • vue中使用cookie

    1、安装 2、在main.js中引用 3、代码 请求login接口后将userId保存到cookie中 ,发出请求...

  • VUE.JS 在django发送认证信息

    1、在使用VUE.js进行用户认证时,可以使用RESTful,reqwest.js,Cookie.js进行操作。 ...

  • 使用vue-cookies操作cookie

    1.前言 在vue中如果想要操作cookie,除了使用之前我们自己封装好的操作cookie的方法之外,我们还可以使...

  • J2EE--Cookie

    为什么要使用Cookie? 怎样使用Cookie? Cookie使用缺陷 Cookie使用示例 1. 为什么要使用...

  • 设置,读取cookie的方法

    因为cookie读取需要通过域名来的,需要使用服务器来运行,我这里使用vue脚手架来运行的

  • SDWebImage与Cookie

    使用Cookie -设置SDWebImageHandleCookies使用Cookie 储存Cookie -设置H...

  • 仿 VIP

    技术栈 Vue、Vue Router、NodeJS、MongoDB、memory-cache、js-cookie、...

网友评论

    本文标题:VUE使用cookie

    本文链接:https://www.haomeiwen.com/subject/fzxlfqtx.html