Evan You 9 лет назад
Родитель
Сommit
8298323108
1 измененных файлов с 4 добавлено и 1 удалено
  1. 4 1
      src/compiler/parser/index.js

+ 4 - 1
src/compiler/parser/index.js

@@ -115,12 +115,12 @@ export function parse (
         processFor(element)
         processIf(element)
         processOnce(element)
+        processKey(element)
 
         // determine whether this is a plain element after
         // removing structural attributes
         element.plain = !element.key && !attrs.length
 
-        processKey(element)
         processRef(element)
         processSlot(element)
         processComponent(element)
@@ -258,6 +258,9 @@ function processRawAttrs (el) {
 function processKey (el) {
   const exp = getBindingAttr(el, 'key')
   if (exp) {
+    if (process.env.NODE_ENV !== 'production' && el.tag === 'template') {
+      warn(`<template> cannot be keyed. Place the key on real elements instead.`)
+    }
     el.key = exp
   }
 }