[improvement] props default value (#2183)

This commit is contained in:
neverland 2018-11-29 22:20:42 +08:00 committed by GitHub
parent ad5121286b
commit 916dbd9927
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
31 changed files with 83 additions and 167 deletions

View File

@ -67,13 +67,10 @@ export default create({
mixins: [Popup], mixins: [Popup],
props: { props: {
value: Boolean,
title: String, title: String,
value: Boolean,
actions: Array,
cancelText: String, cancelText: String,
actions: {
type: Array,
default: () => []
},
overlay: { overlay: {
type: Boolean, type: Boolean,
default: true default: true

View File

@ -144,6 +144,7 @@ export default create({
validator: Function, validator: Function,
showDelete: Boolean, showDelete: Boolean,
showPostal: Boolean, showPostal: Boolean,
searchResult: Array,
showSetDefault: Boolean, showSetDefault: Boolean,
showSearchResult: Boolean, showSearchResult: Boolean,
saveButtonText: String, saveButtonText: String,
@ -164,10 +165,6 @@ export default create({
type: Object, type: Object,
default: () => ({ ...defaultData }) default: () => ({ ...defaultData })
}, },
searchResult: {
type: Array,
default: () => []
},
telValidator: { telValidator: {
type: Function, type: Function,
default: validateMobile default: validateMobile

View File

@ -60,20 +60,14 @@ export default create({
}, },
props: { props: {
list: Array,
disabledList: Array,
disabledText: String, disabledText: String,
addButtonText: String, addButtonText: String,
value: [String, Number], value: [String, Number],
switchable: { switchable: {
type: Boolean, type: Boolean,
default: true default: true
},
list: {
type: Array,
default: () => []
},
disabledList: {
type: Array,
default: () => []
} }
} }
}); });

View File

@ -27,11 +27,8 @@ export default create({
}, },
props: { props: {
...Picker.props,
value: String, value: String,
title: String,
loading: Boolean,
itemHeight: Number,
visibleItemCount: Number,
areaList: { areaList: {
type: Object, type: Object,
default: () => ({}) default: () => ({})
@ -45,7 +42,7 @@ export default create({
data() { data() {
return { return {
code: this.value, code: this.value,
columns: [{ values: [] }, { values: [] }, { values: [] }] cols: [{ values: [] }, { values: [] }, { values: [] }]
}; };
}, },
@ -63,7 +60,7 @@ export default create({
}, },
displayColumns() { displayColumns() {
return this.columns.slice(0, +this.columnsNum); return this.cols.slice(0, +this.columnsNum);
} }
}, },

View File

@ -11,12 +11,9 @@ export default create({
name: 'checkbox-group', name: 'checkbox-group',
props: { props: {
max: Number,
value: Array, value: Array,
disabled: Boolean, disabled: Boolean
max: {
type: Number,
default: 0
}
}, },
watch: { watch: {

View File

@ -47,9 +47,9 @@ export default create({
mixins: [findParent], mixins: [findParent],
props: { props: {
name: [String, Number],
icon: String, icon: String,
label: String, label: String,
name: [String, Number],
title: [String, Number], title: [String, Number],
value: [String, Number], value: [String, Number],
disabled: Boolean, disabled: Boolean,

View File

@ -50,12 +50,9 @@ export default create({
}, },
props: { props: {
value: {}, value: null,
addText: String, list: Array,
list: { addText: String
type: Array,
default: () => []
}
} }
}); });
</script> </script>

View File

@ -21,14 +21,11 @@ export default create({
props: { props: {
title: String, title: String,
coupons: Array,
border: { border: {
type: Boolean, type: Boolean,
default: true default: true
}, },
coupons: {
type: Array,
default: () => []
},
chosenCoupon: { chosenCoupon: {
type: Number, type: Number,
default: -1 default: -1

View File

@ -103,6 +103,8 @@ export default create({
props: { props: {
code: String, code: String,
coupons: Array,
disabledCoupons: Array,
closeButtonText: String, closeButtonText: String,
inputPlaceholder: String, inputPlaceholder: String,
exchangeButtonText: String, exchangeButtonText: String,
@ -116,14 +118,6 @@ export default create({
type: Number, type: Number,
default: -1 default: -1
}, },
coupons: {
type: Array,
default: () => []
},
disabledCoupons: {
type: Array,
default: () => []
},
displayedCouponIndex: { displayedCouponIndex: {
type: Number, type: Number,
default: -1 default: -1

View File

@ -2,7 +2,7 @@
<picker <picker
ref="picker" ref="picker"
:title="title" :title="title"
:columns="columns" :columns="cols"
:item-height="itemHeight" :item-height="itemHeight"
:show-toolbar="showToolbar" :show-toolbar="showToolbar"
:visible-item-count="visibleItemCount" :visible-item-count="visibleItemCount"
@ -30,12 +30,10 @@ export default create({
}, },
props: { props: {
...Picker.props,
value: null, value: null,
title: String, minHour: Number,
itemHeight: Number, minMinute: Number,
visibleItemCount: Number,
confirmButtonText: String,
cancelButtonText: String,
type: { type: {
type: String, type: String,
default: 'datetime' default: 'datetime'
@ -62,18 +60,10 @@ export default create({
default: () => new Date(currentYear + 10, 11, 31), default: () => new Date(currentYear + 10, 11, 31),
validator: isValidDate validator: isValidDate
}, },
minHour: {
type: Number,
default: 0
},
maxHour: { maxHour: {
type: Number, type: Number,
default: 23 default: 23
}, },
minMinute: {
type: Number,
default: 0
},
maxMinute: { maxMinute: {
type: Number, type: Number,
default: 59 default: 59
@ -97,7 +87,7 @@ export default create({
this.$emit('input', val); this.$emit('input', val);
}, },
columns() { cols() {
this.updateColumnValue(this.innerValue); this.updateColumnValue(this.innerValue);
} }
}, },
@ -148,7 +138,7 @@ export default create({
return result; return result;
}, },
columns() { cols() {
const results = this.ranges.map(({ type, range }) => { const results = this.ranges.map(({ type, range }) => {
const values = this.times(range[1] - range[0] + 1, index => { const values = this.times(range[1] - range[0] + 1, index => {
let value = range[0] + index; let value = range[0] + index;

View File

@ -59,19 +59,13 @@ export default create({
}, },
props: { props: {
images: Array,
startPosition: Number,
showIndicators: Boolean, showIndicators: Boolean,
images: {
type: Array,
default: () => []
},
loop: { loop: {
type: Boolean, type: Boolean,
default: true default: true
}, },
startPosition: {
type: Number,
default: 0
},
overlay: { overlay: {
type: Boolean, type: Boolean,
default: true default: true

View File

@ -55,12 +55,6 @@ export default {
'https://img.yzcdn.cn/public_files/2017/09/05/8a4f5be8289cb3a7434fc19a3de780a2.jpg' 'https://img.yzcdn.cn/public_files/2017/09/05/8a4f5be8289cb3a7434fc19a3de780a2.jpg'
] ]
}; };
},
methods: {
handleComponentShow() {
console.log('component show');
}
} }
}; };
</script> </script>

View File

@ -16,8 +16,8 @@ export default {
name: 'modal', name: 'modal',
props: { props: {
visible: Boolean,
zIndex: Number, zIndex: Number,
visible: Boolean,
className: String, className: String,
customStyle: Object customStyle: Object
}, },

View File

@ -16,11 +16,8 @@ export default create({
name: 'key', name: 'key',
props: { props: {
text: [String, Number], type: Array,
type: { text: [String, Number]
type: Array,
default: () => []
}
}, },
data() { data() {

View File

@ -42,6 +42,7 @@ export default create({
prevText: String, prevText: String,
nextText: String, nextText: String,
pageCount: Number, pageCount: Number,
totalItems: Number,
forceEllipses: Boolean, forceEllipses: Boolean,
mode: { mode: {
type: String, type: String,
@ -54,10 +55,6 @@ export default create({
showPageSize: { showPageSize: {
type: Number, type: Number,
default: 5 default: 5
},
totalItems: {
type: Number,
default: 0
} }
}, },

View File

@ -38,15 +38,9 @@ export default create({
valueKey: String, valueKey: String,
className: String, className: String,
itemHeight: Number, itemHeight: Number,
visibleItemCount: Number, defaultIndex: Number,
initialOptions: { initialOptions: Array,
type: Array, visibleItemCount: Number
default: () => []
},
defaultIndex: {
type: Number,
default: 0
}
}, },
data() { data() {

View File

@ -71,6 +71,7 @@ export default create({
props: { props: {
title: String, title: String,
columns: Array,
loading: Boolean, loading: Boolean,
showToolbar: Boolean, showToolbar: Boolean,
confirmButtonText: String, confirmButtonText: String,
@ -86,10 +87,6 @@ export default create({
itemHeight: { itemHeight: {
type: Number, type: Number,
default: 44 default: 44
},
columns: {
type: Array,
default: () => []
} }
}, },

View File

@ -1,7 +1,7 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`column watch default index 1`] = ` exports[`column watch default index 1`] = `
<div class="van-picker-column"> <div class="van-picker-column" style="height: 0px;">
<ul style="line-height: 50px;"> <ul style="line-height: 50px;">
<li class="van-ellipsis van-picker-column__item van-picker-column__item--disabled" style="height: 50px;">1</li> <li class="van-ellipsis van-picker-column__item van-picker-column__item--disabled" style="height: 50px;">1</li>
<li class="van-ellipsis van-picker-column__item van-picker-column__item--selected" style="height: 50px;">1990</li> <li class="van-ellipsis van-picker-column__item van-picker-column__item--selected" style="height: 50px;">1990</li>
@ -15,7 +15,7 @@ exports[`column watch default index 1`] = `
`; `;
exports[`column watch default index 2`] = ` exports[`column watch default index 2`] = `
<div class="van-picker-column"> <div class="van-picker-column" style="height: 0px;">
<ul style="line-height: 50px;"> <ul style="line-height: 50px;">
<li class="van-ellipsis van-picker-column__item van-picker-column__item--disabled" style="height: 50px;">1</li> <li class="van-ellipsis van-picker-column__item van-picker-column__item--disabled" style="height: 50px;">1</li>
<li class="van-ellipsis van-picker-column__item" style="height: 50px;">1990</li> <li class="van-ellipsis van-picker-column__item" style="height: 50px;">1990</li>

View File

@ -20,6 +20,7 @@ export default create({
mixins: [Popup], mixins: [Popup],
props: { props: {
position: String,
transition: String, transition: String,
overlay: { overlay: {
type: Boolean, type: Boolean,
@ -28,16 +29,12 @@ export default create({
closeOnClickOverlay: { closeOnClickOverlay: {
type: Boolean, type: Boolean,
default: true default: true
},
position: {
type: String,
default: ''
} }
}, },
computed: { computed: {
currentTransition() { currentTransition() {
return this.transition || (this.position === '' ? 'van-fade' : `popup-slide-${this.position}`); return this.transition || (this.position ? `popup-slide-${this.position}` : 'van-fade');
} }
} }
}); });

View File

@ -23,6 +23,7 @@ export default create({
name: 'rate', name: 'rate',
props: { props: {
value: Number,
readonly: Boolean, readonly: Boolean,
disabled: Boolean, disabled: Boolean,
size: { size: {
@ -52,10 +53,6 @@ export default create({
count: { count: {
type: Number, type: Number,
default: 5 default: 5
},
value: {
type: Number,
default: 0
} }
}, },

View File

@ -160,11 +160,13 @@ export default create({
props: { props: {
sku: Object, sku: Object,
goods: Object, goods: Object,
quota: Number,
value: Boolean, value: Boolean,
buyText: String, buyText: String,
quotaUsed: Number,
goodsId: [Number, String], goodsId: [Number, String],
stepperTitle: String,
hideStock: Boolean, hideStock: Boolean,
stepperTitle: String,
getContainer: Function, getContainer: Function,
resetStepperOnHide: Boolean, resetStepperOnHide: Boolean,
resetSelectedSkuOnHide: Boolean, resetSelectedSkuOnHide: Boolean,
@ -174,14 +176,6 @@ export default create({
type: Object, type: Object,
default: () => ({}) default: () => ({})
}, },
quota: {
type: Number,
default: 0
},
quotaUsed: {
type: Number,
default: 0
},
showAddCartBtn: { showAddCartBtn: {
type: Boolean, type: Boolean,
default: true default: true

View File

@ -62,10 +62,7 @@ export default create({
props: { props: {
value: String, value: String,
uploadImg: { uploadImg: Function,
type: Function,
required: true
},
maxSize: { maxSize: {
type: Number, type: Number,
default: 6 default: 6

View File

@ -42,15 +42,15 @@ export default create({
}, },
props: { props: {
skuEventBus: Object,
skuStockNum: Number,
selectedSku: Object,
selectedSkuComb: Object,
selectedNum: Number,
stepperTitle: String,
quota: Number, quota: Number,
quotaUsed: Number, quotaUsed: Number,
hideStock: Boolean, hideStock: Boolean,
skuEventBus: Object,
skuStockNum: Number,
selectedSku: Object,
selectedNum: Number,
stepperTitle: String,
selectedSkuComb: Object,
disableStepperInput: Boolean, disableStepperInput: Boolean,
customStepperConfig: Object customStepperConfig: Object
}, },

View File

@ -28,23 +28,17 @@ export default create({
mixins: [Touch], mixins: [Touch],
props: { props: {
min: Number,
value: Number,
disabled: Boolean, disabled: Boolean,
max: { max: {
type: Number, type: Number,
default: 100 default: 100
}, },
min: {
type: Number,
default: 0
},
step: { step: {
type: Number, type: Number,
default: 1 default: 1
}, },
value: {
type: Number,
default: 0
},
barHeight: { barHeight: {
type: String, type: String,
default: '2px' default: '2px'

View File

@ -42,7 +42,6 @@ export default create({
props: { props: {
tip: String, tip: String,
type: Number,
price: Number, price: Number,
label: String, label: String,
loading: Boolean, loading: Boolean,

View File

@ -47,14 +47,8 @@ export default create({
props: { props: {
onClose: Function, onClose: Function,
disabled: Boolean, disabled: Boolean,
leftWidth: { leftWidth: Number,
type: Number, rightWidth: Number
default: 0
},
rightWidth: {
type: Number,
default: 0
}
}, },
directives: { directives: {

View File

@ -41,6 +41,7 @@ export default create({
height: Number, height: Number,
autoplay: Number, autoplay: Number,
vertical: Boolean, vertical: Boolean,
initialSwipe: Number,
indicatorColor: String, indicatorColor: String,
loop: { loop: {
type: Boolean, type: Boolean,
@ -50,10 +51,6 @@ export default create({
type: Boolean, type: Boolean,
default: true default: true
}, },
initialSwipe: {
type: Number,
default: 0
},
showIndicators: { showIndicators: {
type: Boolean, type: Boolean,
default: true default: true

View File

@ -12,7 +12,6 @@
text-align: center; text-align: center;
box-sizing: border-box; box-sizing: border-box;
background-color: @white; background-color: @white;
transition: color .3s;
span { span {
display: block; display: block;

View File

@ -73,8 +73,12 @@ export default create({
color: String, color: String,
sticky: Boolean, sticky: Boolean,
animated: Boolean, animated: Boolean,
lineWidth: Number, offsetTop: Number,
swipeable: Boolean, swipeable: Boolean,
lineWidth: {
type: Number,
default: null
},
active: { active: {
type: [Number, String], type: [Number, String],
default: 0 default: 0
@ -90,10 +94,6 @@ export default create({
swipeThreshold: { swipeThreshold: {
type: Number, type: Number,
default: 4 default: 4
},
offsetTop: {
type: Number,
default: 0
} }
}, },

View File

@ -42,14 +42,8 @@ export default create({
name: 'tree-select', name: 'tree-select',
props: { props: {
items: { items: Array,
type: Array, mainActiveIndex: Number,
default: () => []
},
mainActiveIndex: {
type: Number,
default: 0
},
activeId: { activeId: {
type: [Number, String], type: [Number, String],
default: 0 default: 0

View File

@ -6,10 +6,30 @@ import bem from '../mixins/bem';
import i18n from '../mixins/i18n'; import i18n from '../mixins/i18n';
import { isDef } from './'; import { isDef } from './';
const install = function(Vue) { function install(Vue) {
Vue.component(this.name, this); 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) { export default function(sfc) {
sfc.name = 'van-' + sfc.name; sfc.name = 'van-' + sfc.name;
sfc.install = sfc.install || install; sfc.install = sfc.install || install;
@ -17,6 +37,7 @@ export default function(sfc) {
sfc.mixins.push(i18n, bem); sfc.mixins.push(i18n, bem);
sfc.methods = sfc.methods || {}; sfc.methods = sfc.methods || {};
sfc.methods.isDef = isDef; sfc.methods.isDef = isDef;
sfc.props && defaultProps(sfc.props);
return sfc; return sfc;
}; }