Przeglądaj źródła

warn undefined render/template during SSR

Evan You 9 lat temu
rodzic
commit
7c3db415a7
1 zmienionych plików z 14 dodań i 6 usunięć
  1. 14 6
      src/server/render.js

+ 14 - 6
src/server/render.js

@@ -18,12 +18,20 @@ const normalizeAsync = (cache, method) => {
 const compilationCache = Object.create(null)
 const normalizeRender = vm => {
   const { render, template } = vm.$options
-  if (!render && template) {
-    const renderFns = (
-      compilationCache[template] ||
-      (compilationCache[template] = compileToFunctions(template))
-    )
-    Object.assign(vm.$options, renderFns)
+  if (!render) {
+    if (template) {
+      const renderFns = (
+        compilationCache[template] ||
+        (compilationCache[template] = compileToFunctions(template))
+      )
+      Object.assign(vm.$options, renderFns)
+    } else {
+      throw new Error(
+        `render function or template not defined in component: ${
+          vm.$options.name || vm.$options._componentTag || 'anonymous'
+        }`
+      )
+    }
   }
 }