## Storage 定时存储
将字符串、数组、对象、数字...存储到本地,设置存储有效时间。常用于登录后用户信息存储等...
![](https://img.kancloud.cn/46/22/4622b585059b9092c23e90522a4f4783_1259x93.png =600x)
### 代码示例
```javascript
<template>
<div class="page">
<cvu-row :gutter="16">
<cvu-col span="10"><Input v-model="copyText" placeholder="请输入文本内容" clearable></Input></cvu-col>
<cvu-col span="12">
<cvu-button-group>
<cvu-button type="primary" @on-click="handleSetItem">设置缓存</cvu-button>
<cvu-button type="success" @on-click="handleGetItem">获取缓存</cvu-button>
<cvu-button type="warning" @on-click="handleRemoveItem">删除缓存</cvu-button>
<cvu-button type="danger" @on-click="handleClearItem">清空缓存</cvu-button>
</cvu-button-group>
</cvu-col>
</cvu-row>
</div>
</template>
<script>
export default {
data() {
return {
copyText: ''
}
},
methods: {
handleSetItem() {
if(!this.copyText) {
this.$Message.warning('请输入文本内容')
return
}
this.$cvuStorage.setItem({
key: 'storageData',
value: this.copyText,
time: 1 * 60
})
this.$Message.success('设置存储成功')
this.copyText = ''
},
handleGetItem() {
this.copyText = this.$cvuStorage.getItem({
key: 'storageData'
})
this.$Message.success('获取存储成功')
},
handleRemoveItem() {
this.$cvuStorage.removeItem({
key: 'storageData'
})
this.$Message.success('删除存储成功')
this.copyText = ''
},
handleClearItem() {
this.$cvuStorage.clearItem()
this.$Message.success('清空存储成功')
this.copyText = ''
}
}
}
</script>
<style lang="scss" scoped>
.page{
height: 100%;
padding: 15px;
box-sizing: border-box;
h3{
margin: 10px 0;
}
/deep/.ivu-input{
height: 40px;
line-height: 40px;
}
}
</style>
```
### methods
设置存储
>[success] `this.$cvuStorage.setItem(options)`
- options:
- key:数据键名
- value:数据内容 (String/Boolean/Number/Array/Object)
- time:有效时间,单位:s
- type:存储工具名(localStorage[默认]/sessionStorage)
获取存储
>[success] `this.$cvuStorage.getItem(options)`
- options:
- key:数据键名
- type:存储工具名(localStorage[默认]/sessionStorage)
删除存储
>[success] `this.$cvuStorage.removeItem(options)`
- options:
- key:数据键名
- type:存储工具名(localStorage[默认]/sessionStorage)
清空存储
>[success] `this.$cvuStorage.clearItem(options)`
- options:
- type:存储工具名(localStorage[默认]/sessionStorage)
- 介绍
- 安装
- 快速上手
- 组件
- 基础
- Button 按钮
- ButtonGroup 按钮组
- 布局
- Card 卡片
- Col 列
- Collapse 折叠面板
- Divider 分割线
- Empty 空数据
- Row 行
- 导航
- Paginator 分页
- PaginatorMini 分页
- Tab 标签页
- 表单
- Cascader 级联选择
- PasswordStrength 密码强度
- Print 局部打印
- Table 表格
- Upload 文件上传
- 视图
- Calendar 日历
- Drawer 抽屉
- Loading 加载
- Message 全局提示
- Modal 对话框
- Notification 通知菜单
- Poptip 气泡提示
- Preview 图片预览
- PreviewPdf pdf文件预览
- Tooltip 文字提示
- Tree 树形控件
- 方法
- Copy 复制到剪贴板
- DescNotice 桌面消息通知
- Html2Pdf 导出pdf
- Storage 定时存储
- 其他
- BackTop 返回顶部
- NumberScroll 数字动画
- NumberZero 数字前补零
- Spin 局部加载
- Tcplayer 播放器