@form-create/core
Version:
FormCreate低代码表单渲染引擎,可以通过 JSON 生成具有动态渲染、数据收集、验证和提交功能的低代码表单。支持6个UI框架,适配移动端,并且支持生成任何 Vue 组件。
45 lines (42 loc) • 1.22 kB
JavaScript
import extend from '@form-create/utils/lib/extend';
export default function useCache(Render) {
extend(Render.prototype, {
initCache() {
this.clearCacheAll();
},
clearCache(ctx) {
if(ctx.rule.cache){
return;
}
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,
slot: ctx.rule.slot
};
},
getCache(ctx) {
const cache = this.cache[ctx.id];
if (cache) {
cache.use = true;
return cache.vnode;
}
return undefined;
}
})
}