npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

vue-intelligent-cookie

v1.1.0

Published

[vue智能数据持久化插件] A Vue.js plugin for intelligent manipulating cache

Downloads

12

Readme

vue-intelligent-cookie

智能数据持久化插件

  • 0依赖
  • 自动判断LocalStorage、cookie是否可用
  • 解决特殊浏览器或者部分浏览器在无痕模式下,LocalStorage、cookie读写失败的问题
  • LocalStorage、cookie均不可用时,使用内置数据存储方案

运行原理

  • 项目基于高人气项目tiny-cookie,vue-cookie,localstorage-cookie重构开发
  • 初始化前,判断LocalStorage、cookie的可用性,默认优先使用localStorage,再尝试cookie
  • 若两者都不可用,则将缓存保存在运行实例中,保证前端程序的正确运行

特别功能

  • 可直接存储对象;
  • 为LocalStorage拓展实现cookie的参数机制
  • 当前采用的运行机制可以控制台查看window.IntelligentCookie.storageMode

Installation

Install through npm


npm install vue-intelligent-cookie --save

Include in <body> after loading Vue and it will automatically hook into Vue


<script src="/node_modules/vue-intelligent-cookie/dist/min.js'"></script>
or
<script src="/node_modules/vue-intelligent-cookie/src/vue-intelligent-cookie.js'"></script>

Or do it the cool way and load it in your main.js/app.js


// Require dependencies
var Vue = require('vue');
var IntelligentCookie = require('vue-intelligent-cookie');
// Tell Vue to use the plugin
Vue.use(IntelligentCookie);

Usage

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

Example

// 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');
Advanced examples

// 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' });

Thanks for using the plugin, I am happy to accept feedback/pull requests, do not forget to star if you like it!

Happy Coding! :D

下个版本开发计划

  • 可配置默认存储
  • ts支持
  • 添加会话存储

Thanks

tiny-cookie

vue-cookie

localstorage-cookie