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

support using actual component constructors in :is

Evan You 10 лет назад
Родитель
Сommit
82767a0372

+ 8 - 3
src/directives/internal/component.js

@@ -118,12 +118,17 @@ export default {
 
   resolveComponent (id, cb) {
     var self = this
-    this.pendingComponentCb = cancellable(function (Component) {
+    var done = function (Component) {
       self.ComponentName = Component.options.name || id
       self.Component = Component
       cb()
-    })
-    this.vm._resolveComponent(id, this.pendingComponentCb)
+    }
+    if (typeof id === 'function') {
+      done(id)
+    } else {
+      this.pendingComponentCb = cancellable(done)
+      this.vm._resolveComponent(id, this.pendingComponentCb)
+    }
   },
 
   /**

+ 13 - 0
test/unit/specs/directives/internal/component_spec.js

@@ -134,6 +134,19 @@ describe('Component', function () {
     })
   })
 
+  it(':is using raw component constructor', function () {
+    new Vue({
+      el: el,
+      template: '<component :is="$options.components.test">',
+      components: {
+        test: {
+          template: 'hi'
+        }
+      }
+    })
+    expect(el.textContent).toBe('hi')
+  })
+
   it('keep-alive', function (done) {
     var spyA = jasmine.createSpy()
     var spyB = jasmine.createSpy()