Ver Fonte

ensure prop default value when instantiating without propsData (fix #3693)

Evan You há 9 anos atrás
pai
commit
037449f453
2 ficheiros alterados com 2 adições e 4 exclusões
  1. 1 1
      src/core/instance/state.js
  2. 1 3
      src/core/util/props.js

+ 1 - 1
src/core/instance/state.js

@@ -32,8 +32,8 @@ export function initState (vm: Component) {
 
 function initProps (vm: Component) {
   const props = vm.$options.props
-  const propsData = vm.$options.propsData
   if (props) {
+    const propsData = vm.$options.propsData || {}
     const keys = vm.$options._propKeys = Object.keys(props)
     const isRoot = !vm.$parent
     // root instance props should be converted

+ 1 - 3
src/core/util/props.js

@@ -14,11 +14,9 @@ type PropOptions = {
 export function validateProp (
   key: string,
   propOptions: Object,
-  propsData: ?Object,
+  propsData: Object,
   vm?: Component
 ): any {
-  /* istanbul ignore if */
-  if (!propsData) return
   const prop = propOptions[key]
   const absent = !hasOwn(propsData, key)
   let value = propsData[key]