Просмотр исходного кода

support alternative prop syntax

Evan You 11 лет назад
Родитель
Сommit
81911b4491
1 измененных файлов с 15 добавлено и 0 удалено
  1. 15 0
      src/util/options.js

+ 15 - 0
src/util/options.js

@@ -232,6 +232,20 @@ function guardComponents (components) {
   }
 }
 
+function guardProps (child) {
+  var props = child.props
+  if (_.isPlainObject(props)) {
+    child.props = Object.keys(props).map(function (key) {
+      var val = props[key]
+      if (!_.isPlainObject(val)) {
+        val = { type: val }
+      }
+      val.name = key
+      return val
+    })
+  }
+}
+
 /**
  * Merge two option objects into a new one.
  * Core utility used in both instantiation and inheritance.
@@ -244,6 +258,7 @@ function guardComponents (components) {
 
 exports.mergeOptions = function merge (parent, child, vm) {
   guardComponents(child.components)
+  guardProps(child)
   var options = {}
   var key
   if (child.mixins) {