UNPKG

hot-form

Version:

A project developed based on ant-design-vue and vant whitch do some things on create/render/modify and etc. for forms. Also can custom some component on the form items if you want. 一个基于antdv/vant开发的创建表单组件,包含表单渲染、表单编辑页面、以及植入自定义附加内容的组件

41 lines (37 loc) 1.21 kB
import { defineReadonly } from '@/libs'; import * as methods from './methods'; import components from './components'; // 扩展属性方法 const addProperties = (value, Ctor) => { // new Vue const vm = new Ctor(); // Vue.prototype const proto = Ctor.prototype; // [...new Vue().properties, ...Vue.properties] // 获取vue已有的属性和已经绑定在Vue上的属性 const vmProperties = Object.keys(proto).concat(Object.keys(vm)); // Object.entries: { key1: value1, key2: value2 } -> [[key1, value1], [key2, value2]] Object.entries(value).forEach(([key, property]) => { if (vmProperties.includes(key)) { throw new Error('property ', key, 'has existed!'); } defineReadonly(proto, key, property); }); } // 扩展组件方法 const addComponents = (value, Ctor) => { Object.entries(value).forEach(([key, component]) => { if (Ctor.component(key)) { throw new Error("component '" + key + "' has existed!"); } Ctor.component(key, component); }); } export default { async install(Vue) { // 扩展业务方法 addProperties(methods, Vue); // 扩展组件 addComponents(components, Vue); }, }