mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
40 lines
703 B
JavaScript
40 lines
703 B
JavaScript
/**
|
|
* 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;
|
|
};
|