mirror of
https://github.com/zuiidea/antd-admin
synced 2026-10-21 06:53:47 +00:00
16 lines
497 B
JavaScript
16 lines
497 B
JavaScript
const Mock = require('mockjs')
|
|
const Watch = require("watchjs")
|
|
import config from './config'
|
|
|
|
export default function mockStorge(name, defaultValue) {
|
|
let key = config.prefix + name
|
|
global[key] = localStorage.getItem(key)
|
|
? JSON.parse(localStorage.getItem(key))
|
|
: defaultValue
|
|
!localStorage.getItem(key) && localStorage.setItem(key, JSON.stringify(global[key]))
|
|
Watch.watch(global[key], function () {
|
|
localStorage.setItem(key, JSON.stringify(global[key]))
|
|
})
|
|
return key
|
|
}
|