Add more valid

This commit is contained in:
Harvey committed 2021-12-10 11:05:44 +08:00
1 parent 5f45ad112f
commit d919471838
7 files changed
+31 -11

No files matched your search

@@ -1,4 +1,6 @@
import { hasClass, addClass, removeClass, append, setStyles, tooltip, getStyle, inverseClass } from './dom';
import validator from 'option-validator';
import { ComponentOption } from '../scheme';
import { has, def } from './property';
import { errorHandle } from './error';
@@ -32,6 +34,9 @@ export default class Component {
add(getOption) {
const option = typeof getOption === 'function' ? getOption(this.art) : getOption;
option.html = option.html || '';
validator(option, ComponentOption);
if (!this.$parent || !this.name || option.disable) return;
const name = option.name || `${this.name}${this.id}`;
errorHandle(!has(this, name), `Cannot add an existing name [${name}] to the [${this.name}]`);