Răsfoiți Sursa

enable recursive lookup with "name" option

Evan You 10 ani în urmă
părinte
comite
7998deb775
1 a modificat fișierele cu 6 adăugiri și 5 ștergeri
  1. 6 5
      src/api/global.js

+ 6 - 5
src/api/global.js

@@ -36,11 +36,8 @@ var cid = 1
 exports.extend = function (extendOptions) {
   extendOptions = extendOptions || {}
   var Super = this
-  var Sub = createClass(
-    extendOptions.name ||
-    Super.options.name ||
-    'VueComponent'
-  )
+  var name = extendOptions.name || Super.options.name
+  var Sub = createClass(name || 'VueComponent')
   Sub.prototype = Object.create(Super.prototype)
   Sub.prototype.constructor = Sub
   Sub.cid = cid++
@@ -56,6 +53,10 @@ exports.extend = function (extendOptions) {
   config._assetTypes.forEach(function (type) {
     Sub[type] = Super[type]
   })
+  // enable recursive self-lookup
+  if (name) {
+    Sub.options.components[name] = Sub
+  }
   return Sub
 }