Skip to content

Commit 9b26dfa

Browse files
committed
chore: fix getProps bug
1 parent 4d3134b commit 9b26dfa

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

components/_util/props-util.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import isPlainObject from 'lodash/isPlainObject'
22

3+
function getType (fn) {
4+
const match = fn && fn.toString().match(/^\s*function (\w+)/)
5+
return match ? match[1] : ''
6+
}
7+
38
const camelizeRE = /-(\w)/g
49
const camelize = (str) => {
510
return str.replace(camelizeRE, (_, c) => c ? c.toUpperCase() : '')
@@ -67,8 +72,11 @@ const getOptionProps = (instance) => {
6772
const props = (Ctor.options || {}).props || {}
6873
const res = {}
6974
for (const [k, v] of Object.entries(props)) {
70-
if (v.default !== undefined) {
71-
res[k] = typeof v.default === 'function' ? v.default() : v.default
75+
const def = v.default
76+
if (def !== undefined) {
77+
res[k] = typeof def === 'function' && getType(v.type) !== 'Function'
78+
? def.call(instance)
79+
: def
7280
}
7381
}
7482
return { ...res, ...propsData }

0 commit comments

Comments
 (0)