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

fix(compiler): fix codegen for v-for component inside template

fix #9142
Evan You 7 лет назад
Родитель
Сommit
1b4a8a0c1e
2 измененных файлов с 9 добавлено и 3 удалено
  1. 1 3
      src/compiler/codegen/index.js
  2. 8 0
      test/unit/modules/compiler/codegen.spec.js

+ 1 - 3
src/compiler/codegen/index.js

@@ -406,9 +406,7 @@ export function genChildren (
       el.tag !== 'template' &&
       el.tag !== 'slot'
     ) {
-      // because el may be a functional component and return an Array instead of a single root.
-      // In this case, just a simple normalization is needed
-      const normalizationType = state.maybeComponent(el) ? `,1` : ``
+      const normalizationType = checkSkip && state.maybeComponent(el) ? `,1` : ``
       return `${(altGenElement || genElement)(el, state)}${normalizationType}`
     }
     const normalizationType = checkSkip

+ 8 - 0
test/unit/modules/compiler/codegen.spec.js

@@ -631,5 +631,13 @@ describe('codegen', () => {
       { isReservedTag }
     )
   })
+
+  // #9142
+  it('should compile single v-for component inside template', () => {
+    assertCodegen(
+      `<div><template v-if="ok"><foo v-for="i in 1" :key="i"></foo></template></div>`,
+      `with(this){return _c('div',[(ok)?_l((1),function(i){return _c('foo',{key:i})}):_e()],2)}`
+    )
+  })
 })
 /* eslint-enable quotes */