UNPKG

vue-django

Version:

个人实验项目, 本框架的目标是借鉴并超越django admin的自动化思想, 实现UI前端的极简快速定制开发

44 lines (42 loc) 960 B
/** * Created by denishuang on 2020/1/7. */ import {duration} from './filters' import {throttle} from 'lodash' export default function (cache) { let t = { value: 0, cache, init () { if (this.cache) { this.value = this.cache.read() || 0 } }, run () { this.handler = setInterval(() => { this.value++ if (this.cache) { this.saveCache() } }, 1000) }, saveCache: throttle(function () { this.cache.save(this.value) }, 10000), stop () { clearInterval(this.handler) }, clear () { this.value = 0 if (this.cache) { this.cache.destroy() } }, toString () { return duration(this.value) } } t.init() t.run() return t }