Przeglądaj źródła

do not throw when component is not found (close #1099)

Evan You 11 lat temu
rodzic
commit
6c51c0a83a

+ 3 - 0
src/instance/misc.js

@@ -55,6 +55,9 @@ exports._resolveComponent = function (id, cb) {
   if (process.env.NODE_ENV !== 'production') {
     _.assertAsset(factory, 'component', id)
   }
+  if (!factory) {
+    return
+  }
   // async component factory
   if (!factory.options) {
     if (factory.resolved) {

+ 9 - 0
test/unit/specs/directives/component_spec.js

@@ -423,5 +423,14 @@ if (_.inBrowser) {
       expect(hasWarned(_, 'cannot mount component "test" on already mounted element')).toBe(true)
     })
 
+    it('not found component should not throw', function () {
+      expect(function () {
+        new Vue({
+          el: el,
+          template: '<div v-component="non-existent"></div>'
+        })
+      }).not.toThrow()
+    })
+
   })
 }