当前位置: 首页 > news >正文

(6)添加vue-cookie

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

#(6)添加vue-cookie

1 安装vue-cookie

cnpm install --save vue-cookie

2 引入

main.js中进行引入:

import Vue from 'vue' //这句是原来就有的
import VueCookie from 'vue-cookie'
Vue.use(VueCookie)

安装引入后就可以使用了

3 使用方法

The plugin is available through this.$cookie in components or Vue.cookie

3.1 例子

// From some method in one of your Vue components
this.$cookie.set('test', 'Hello world!', 1);
// This will set a cookie with the name 'test' and the value 'Hello world!' that expires in one day

// To get the value of a cookie use
this.$cookie.get('test');

// To delete a cookie use
this.$cookie.delete('test');

3.2 高级例子

// Setting the cookie Domain
this.$cookie.set('test', 'Random value', {expires: 1, domain: 'localhost'});

// As this cookie is set with a domain then if you wish to delete it you have to provide the domain when calling delete
this.$cookie.delete('test', {domain: 'localhost'});

// Customizing expires
var date = new Date;
date.setDate(date.getDate() + 21);

this.$cookie.set('dateObject', 'A date object', { expires: date });
this.$cookie.set('dateString', 'A parsable date string', { expires: date.toGMTString() });
this.$cookie.set('integer', 'Seven days later', { expires: 7 });
this.$cookie.set('stringSuffixY', 'One year later', { expires: '1Y' });
this.$cookie.set('stringSuffixM', 'One month later', { expires: '1M' });
this.$cookie.set('stringSuffixD', 'One day later', { expires: '1D' });
this.$cookie.set('stringSuffixh', 'One hour later', { expires: '1h' });
this.$cookie.set('stringSuffixm', 'Ten minutes later', { expires: '10m' });
this.$cookie.set('stringSuffixs', 'Thirty seconds later', { expires: '30s' });

3.3 网上找到的语法

this.$cookies.set(keyName, value[, expireTimes[, path[, domain[, secure]]]])   //return this
this.$cookies.get(keyName)       // return value
this.$cookies.remove(keyName [, path [, domain]])   // return  false or true , warning: next version return this; use isKey(keyname) return true/false,please

参考

https://github.com/alfhen/vue-cookie

转载于:https://my.oschina.net/neumeng/blog/2875863

相关文章:

  • win10下配置java jdk jre环境变量
  • 如何写一个日志采集工具
  • ubuntu linux下解决“no java virtual machine was found after searching the following locations:”的方法...
  • apollo-server 返回模拟数据
  • HTTP--网络协议分层,http历史(二)
  • Java编写基于netty的RPC框架
  • 使用python编写游戏修改器
  • 通过Eclipse 为java 项目生成Api 文档、JavaDoc
  • ios多个target
  • php去除html标签
  • 11月17日站立会议
  • angular搭建
  • 20172307 2018-2019-1 《程序设计与数据结构》第9周学习总结
  • .net core使用RPC方式进行高效的HTTP服务访问
  • 手机里删除的照片怎么恢复,如何恢复
  • Android组件 - 收藏集 - 掘金
  • es6要点
  • Python进阶细节
  • springboot_database项目介绍
  • vue-router 实现分析
  • WePY 在小程序性能调优上做出的探究
  • 阿里云前端周刊 - 第 26 期
  • 百度地图API标注+时间轴组件
  • 持续集成与持续部署宝典Part 2:创建持续集成流水线
  • 从零搭建Koa2 Server
  • 反思总结然后整装待发
  • 如何编写一个可升级的智能合约
  • 入手阿里云新服务器的部署NODE
  • 它承受着该等级不该有的简单, leetcode 564 寻找最近的回文数
  • 写代码的正确姿势
  • 一道闭包题引发的思考
  • 以太坊客户端Geth命令参数详解
  • 看到一个关于网页设计的文章分享过来!大家看看!
  • 蚂蚁金服CTO程立:真正的技术革命才刚刚开始
  • ​云纳万物 · 数皆有言|2021 七牛云战略发布会启幕,邀您赴约
  • ###STL(标准模板库)
  • #Linux(权限管理)
  • (C#)Windows Shell 外壳编程系列4 - 上下文菜单(iContextMenu)(二)嵌入菜单和执行命令...
  • (三)mysql_MYSQL(三)
  • (四)TensorRT | 基于 GPU 端的 Python 推理
  • (推荐)叮当——中文语音对话机器人
  • (译)计算距离、方位和更多经纬度之间的点
  • (最完美)小米手机6X的Usb调试模式在哪里打开的流程
  • *ST京蓝入股力合节能 着力绿色智慧城市服务
  • .net core webapi Startup 注入ConfigurePrimaryHttpMessageHandler
  • .NET Core引入性能分析引导优化
  • .Net Framework 4.x 程序到底运行在哪个 CLR 版本之上
  • .netcore 6.0/7.0项目迁移至.netcore 8.0 注意事项
  • .net访问oracle数据库性能问题
  • .NET高级面试指南专题十一【 设计模式介绍,为什么要用设计模式】
  • .NET开发人员必知的八个网站
  • .NET是什么
  • .pub是什么文件_Rust 模块和文件 - 「译」
  • /dev/VolGroup00/LogVol00:unexpected inconsistency;run fsck manually
  • /usr/lib/mysql/plugin权限_给数据库增加密码策略遇到的权限问题