Vue3报错:'<template v-for>' cannot be keyed. Place the key on real elements instea

5,694 阅读1分钟

报错内容

'<template v-for>' cannot be keyed. Place the key on real elements instead.

报错相关规则链接:eslint.vuejs.org/rules/no-v-…

问题原因

在 Vue 2.x 中,<template> 标签不能拥有 key
在 Vue 3.x 中,key 则应该被设置在 <template> 标签上。 官网链接:结合 <template v-for>

解决方案

  1. .eslintrc.js中的rules添加'vue/no-v-for-template-key': 'off'配置
  2. 将template标签改为div等其他标签