mirror of
https://github.com/youzan/vant.git
synced 2026-03-25 02:01:03 +08:00
[improvement] props default value (#2183)
This commit is contained in:
@@ -6,10 +6,30 @@ import bem from '../mixins/bem';
|
||||
import i18n from '../mixins/i18n';
|
||||
import { isDef } from './';
|
||||
|
||||
const install = function(Vue) {
|
||||
function install(Vue) {
|
||||
Vue.component(this.name, this);
|
||||
};
|
||||
|
||||
function returnArray() {
|
||||
return [];
|
||||
};
|
||||
|
||||
function defaultProps(props) {
|
||||
Object.keys(props).forEach(key => {
|
||||
if (props[key] === Array) {
|
||||
props[key] = {
|
||||
type: Array,
|
||||
default: returnArray
|
||||
};
|
||||
} else if (props[key] === Number) {
|
||||
props[key] = {
|
||||
type: Number,
|
||||
default: 0
|
||||
};
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export default function(sfc) {
|
||||
sfc.name = 'van-' + sfc.name;
|
||||
sfc.install = sfc.install || install;
|
||||
@@ -17,6 +37,7 @@ export default function(sfc) {
|
||||
sfc.mixins.push(i18n, bem);
|
||||
sfc.methods = sfc.methods || {};
|
||||
sfc.methods.isDef = isDef;
|
||||
sfc.props && defaultProps(sfc.props);
|
||||
|
||||
return sfc;
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user