UNPKG

vue-ele-form-yd

Version:

基于 element-ui 的数据驱动表单组件

45 lines (44 loc) 1.44 kB
import componetMixin from './componentMixin' import mock from '../tools/mock' /*********** * 控件对象定义 */ export default { inheritAttrs: false, mixins: [componetMixin], props: { disabled: Boolean, readonly: Boolean, options: { type: Array, default() { return [] } } }, methods: { // 模拟数据 mockData() { const Mock = mock() if (Mock) { if (this.defDesc.mock === true && this.mockRule !== false) { if (this.mockRule === 'custom') { // 自定义mock数据 this.handleChange(this.getCustomMockData()) } else if (this.mockRule === 'checkbox' || this.mockRule === 'radio') { // checkbox 和 radio 类型, 需要传递 options 参数 this.handleChange(Mock.Random[this.mockRule](this.options)) } else if (this.mockRule) { this.handleChange(Mock.mock(this.mockRule)) } else { console.error(this.componentName + ' 类型组件没有mock规则, 请手动配置mock规则, 例如: mock: \'@float\', 详细参考: http://mockjs.com/examples.html#DPD') } } else if (typeof this.defDesc.mock === 'string') { this.handleChange(Mock.mock(this.defDesc.mock)) } else if (typeof this.defDesc.mock === 'function') { this.handleChange(this.defDesc.mock(Mock.mock, Mock.Random)) } } } } }