* Get the default value of a prop.
(vm, prop, key)
| 1302 | * Get the default value of a prop. |
| 1303 | */ |
| 1304 | function getPropDefaultValue (vm, prop, key) { |
| 1305 | // no default, return undefined |
| 1306 | if (!hasOwn(prop, 'default')) { |
| 1307 | return undefined |
| 1308 | } |
| 1309 | var def = prop.default; |
| 1310 | // warn against non-factory defaults for Object & Array |
| 1311 | if (process.env.NODE_ENV !== 'production' && isObject(def)) { |
| 1312 | warn( |
| 1313 | 'Invalid default value for prop "' + key + '": ' + |
| 1314 | 'Props with type Object/Array must use a factory function ' + |
| 1315 | 'to return the default value.', |
| 1316 | vm |
| 1317 | ); |
| 1318 | } |
| 1319 | // the raw prop value was also undefined from previous render, |
| 1320 | // return previous default value to avoid unnecessary watcher trigger |
| 1321 | if (vm && vm.$options.propsData && |
| 1322 | vm.$options.propsData[key] === undefined && |
| 1323 | vm._props[key] !== undefined) { |
| 1324 | return vm._props[key] |
| 1325 | } |
| 1326 | // call factory function for non-Function types |
| 1327 | // a value is Function if its prototype is function even across different execution context |
| 1328 | return typeof def === 'function' && getType(prop.type) !== 'Function' |
| 1329 | ? def.call(vm) |
| 1330 | : def |
| 1331 | } |
| 1332 | |
| 1333 | /** |
| 1334 | * Assert whether a prop is valid. |
no test coverage detected