@caxa-form/core
Version:
vue动态表单,助你轻松搞定表单|form-create is a form generation component that can generate dynamic rendering, data collection, verification and submission functions through JSON. Supports 3 UI frameworks, and supports the generation of any Vue components. Built-in 20
38 lines (35 loc) • 1.03 kB
JavaScript
import extend from '@caxa-form/utils/lib/extend';
export default function useCache(Render) {
extend(Render.prototype, {
initCache() {
this.clearCacheAll();
},
clearCache(ctx) {
if (!this.cache[ctx.id]) {
ctx.parent && this.clearCache(ctx.parent);
return;
}
if (this.cache[ctx.id].use === true || this.cache[ctx.id].parent) {
this.$handle.refresh();
}
const parent = this.cache[ctx.id].parent;
this.cache[ctx.id] = null;
parent && this.clearCache(parent);
},
clearCacheAll() {
this.cache = {};
},
setCache(ctx, vnode, parent) {
this.cache[ctx.id] = {
vnode,
use: false,
parent
};
},
getCache(ctx) {
const cache = this.cache[ctx.id];
cache.use = true;
return cache.vnode;
}
})
}