🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
[TOC] # 插件 store 本地存储 store为需要本地存储的解决方案 ## 使用示例 ```javascript var store = v.store // 存储username为vace store.set('username', 'vace') // 获取 'username' store.get('username') // 删除 'username' store.remove('username') // 清楚所有本地存储,非特殊情况不要使用,会删了队友的- - store.clear() // 可存储对象,内部使用JSON.stringify序列化 store.set('user', { name: 'marcus', likes: 'javascript' }) // 内部会尝试JSON.parse 解析字符串,不用自己解析 var user = store.get('user') alert(user.name + ' likes ' + user.likes) // 获取所有的本地存储 store.getAll().user.name == 'marcus' // 循环读取存储内容 store.forEach(function(key, val) { console.log(key, '==', val) }) ``` ## API使用 * `v.store.set(key,value)` * `v.store.get(key,defaultValue='')` * `v.store.has(key)` * `v.store.remove(key)` * `v.store.clear()` * `v.store.getAll()` * `v.store.forEach(cb)` ## 兼容概览 ------------------ - Tested in iOS 4+ - Tested in Firefox 3.5 - Tested in Firefox 3.6 - Tested in Firefox 4.0+ - Support dropped for Firefox < 3.5 (see notes below) - Tested in Chrome 5 - Tested in Chrome 6 - Tested in Chrome 7 - Tested in Chrome 8 - Tested in Chrome 10 - Tested in Chrome 11+ - Tested in Safari 4 - Tested in Safari 5 - Tested in IE6 - Tested in IE7 - Tested in IE8 - Tested in IE9 - Tested in IE10 - Tested in Opera 10 - Tested in Opera 11 - Tested in Opera 12