[improvement] use component name (#2450)

This commit is contained in:
neverland
2019-01-06 23:08:14 +08:00
committed by GitHub
parent e437e9c10d
commit bf50db9ea0
13 changed files with 87 additions and 76 deletions
+39
View File
@@ -0,0 +1,39 @@
/**
* Create a basic component with common options
*/
import '../../locale';
import { camelize } from '..';
const arrayProp = {
type: Array,
default: () => []
};
const numberProp = {
type: Number,
default: 0
};
function defaultProps(props) {
Object.keys(props).forEach(key => {
if (props[key] === Array) {
props[key] = arrayProp;
} else if (props[key] === Number) {
props[key] = numberProp;
}
});
}
function install(Vue) {
const { name } = this;
Vue.component(name, this);
Vue.component((camelize(`-${name}`)), this);
}
export default name => sfc => {
sfc.name = name;
sfc.install = install;
sfc.props && defaultProps(sfc.props);
return sfc;
};