‘<template>‘ cannot be keyed. Place the key on real elements instead

文章讲述了在Vue.js中不能在<template>元素上直接绑定属性,如:key,提供了一个替代方案,即使用<div>元素进行v-for循环并绑定key属性,以实现动态渲染表格列的效果。
部署运行你感兴趣的模型镜像

原因:

不支持在<template>元素上绑定属性,例如:在以下<template>元素上绑定想要绑定key属性是行不通的

<template v-for="(item, index) in table.columns" :key="index">
        <el-table-column
          :label="item.label"
          :prop="item.prop"
          :width="item.width"
          v-if="item.type == 'slot'"
        >
          <template slot-scope="scope">
            <slot :name="item.slot_name" :row="scope.row" />
          </template>
        </el-table-column>
        <el-table-column
          :label="item.label"
          :prop="item.prop"
          :width="item.width"
          v-else-if="!item.hide"
        ></el-table-column>
      </template>

解决方案:

方案:改用<div>元素

 <div v-for="(item, index) in table.columns" :key="index">
        <el-table-column
          :label="item.label"
          :prop="item.prop"
          :width="item.width"
          v-if="item.type == 'slot'"
        >
          <template slot-scope="scope">
            <slot :name="item.slot_name" :row="scope.row" />
          </template>
        </el-table-column>
        <el-table-column
          :label="item.label"
          :prop="item.prop"
          :width="item.width"
          v-else-if="!item.hide"
        ></el-table-column>
      </div>

您可能感兴趣的与本文相关的镜像

ACE-Step

ACE-Step

音乐合成
ACE-Step

ACE-Step是由中国团队阶跃星辰(StepFun)与ACE Studio联手打造的开源音乐生成模型。 它拥有3.5B参数量,支持快速高质量生成、强可控性和易于拓展的特点。 最厉害的是,它可以生成多种语言的歌曲,包括但不限于中文、英文、日文等19种语言

请根据报错修改新的代码给出: ERROR Failed to compile with 3 errors 17:30:31 error in ./src/pages/mlcs/NewApplication/Mlcs/CompareResult.vue Module Error (from ./node_modules/eslint-loader/index.js): C:\Users\je14902\IdeaProjects\mlcs-web\src\pages\mlcs\NewApplication\Mlcs\CompareResult.vue 117:9 error '<template>' cannot be keyed. Place the key on real elements instead vue/no-template-key 123:15 error Elements in iteration expect to have 'v-bind:key' directives vue/require-v-for-key 126:15 error Elements in iteration expect to have 'v-bind:key' directives vue/require-v-for-key 140:9 error '<template>' cannot be keyed. Place the key on real elements instead vue/no-template-key 145:15 error Elements in iteration expect to have 'v-bind:key' directives vue/require-v-for-key 148:15 error Elements in iteration expect to have 'v-bind:key' directives vue/require-v-for-key 162:9 error '<template>' cannot be keyed. Place the key on real elements instead vue/no-template-key 167:15 error Elements in iteration expect to have 'v-bind:key' directives vue/require-v-for-key 170:15 error Elements in iteration expect to have 'v-bind:key' directives vue/require-v-for-key 184:9 error '<template>' cannot be keyed. Place the key on real elements instead vue/no-template-key 189:15 error Elements in iteration expect to have 'v-bind:key' directives vue/require-v-for-key 192:15 error Elements in iteration expect to have 'v-bind:key' directives vue/require-v-for-key 210:9 error '<template>' cannot be keyed. Place the key on real elements instead vue/no-template-key 215:15 error Elements in iteration expect to have 'v-bind:key' directives vue/require-v-for-key ✖ 14 problems (14 errors, 0 warnings) @ ./src/router/config.js 97:15-71 @ ./src/router/index.js @ ./src/main.js @ multi (webpack)-dev-server/client?http://10.107.112.67:8080&sockPath=/sockjs-node (webpack)/hot/dev-server.js babel-polyfill whatwg-fetch ./src/main.js error in ./src/pages/mlcs/NewApplication/Mlcs/Normal.vue Module Error (from ./node_modules/eslint-loader/index.js): C:\Users\je14902\IdeaProjects\mlcs-web\src\pages\mlcs\NewApplication\Mlcs\Normal.vue 2125:28 error Promise executor functions should not be async no-async-promise-executor ✖ 1 problem (1 error, 0 warnings) @ ./src/router/config.js 67:15-64 @ ./src/router/index.js @ ./src/main.js @ multi (webpack)-dev-server/client?http://10.107.112.67:8080&sockPath=/sockjs-node (webpack)/hot/dev-server.js babel-polyfill whatwg-fetch ./src/main.js error in ./src/pages/mlcs/NewApplication/Mlcs/CompareResult.vue?vue&type=template&id=25a405a5&scoped=true& Module Error (from ./node_modules/vue-loader/lib/loaders/templateLoader.js): (Emitted value instead of an instance of Error) Errors compiling template: <template> cannot be keyed. Place the key on real elements instead. 115| <tbody> 116| <!-- Recipe 不匹配(Photo Area) --> 117| <template v-for="sf in stepForms" :key="'r-' + sf.stepNo"> | ^^^^^^^^^^^^^^^^^^^^^^^ 118| <template v-if="isPhotoArea(sf.area) && sf.stepNo && sf.stepNo.trim()"> 119| <template v-if=" <template> cannot be keyed. Place the key on real elements instead. 138| 139| <!-- Recipe 不匹配(非 Photo Area) --> 140| <template v-for="sf in stepForms" :key="'nr-' + sf.stepNo"> | ^^^^^^^^^^^^^^^^^^^^^^^^ 141| <template v-if="!isPhotoArea(sf.area) && sf.stepNo && sf.stepNo.trim()"> 142| <template v-if=" <template> cannot be keyed. Place the key on real elements instead. 160| 161| <!-- EQP 不匹配 --> 162| <template v-for="sf in stepForms" :key="'eqp-' + sf.stepNo"> | ^^^^^^^^^^^^^^^^^^^^^^^^^ 163| <template v-if="sf.stepNo && sf.stepNo.trim()"> 164| <template v-if=" <template> cannot be keyed. Place the key on real elements instead. 182| 183| <!-- Reticle 不匹配 --> 184| <template v-for="sf in stepForms" :key="'ret-' + sf.stepNo"> | ^^^^^^^^^^^^^^^^^^^^^^^^^ 185| <template v-if="isPhotoArea(sf.area) && sf.stepNo && sf.stepNo.trim()"> 186| <template v-if=" <template> cannot be keyed. Place the key on real elements instead. 208| 209| <!-- Qty 不匹配 --> 210| <template v-for="stepNo in ercAllStep" :key="'qtychk-' + stepNo"> | ^^^^^^^^^^^^^^^^^^^^^^^^^ 211| <template v-if="stepNo && stepNo.trim()"> 212| <template v-if=" @ ./src/pages/mlcs/NewApplication/Mlcs/CompareResult.vue?vue&type=template&id=25a405a5&scoped=true& 1:0-466 1:0-466 @ ./src/pages/mlcs/NewApplication/Mlcs/CompareResult.vue @ ./src/router/config.js @ ./src/router/index.js @ ./src/main.js @ multi (webpack)-dev-server/client?http://10.107.112.67:8080&sockPath=/sockjs-node (webpack)/hot/dev-server.js babel-polyfill whatwg-fetch ./src/main.js WAIT Compiling... 17:32:37 95% emitting ThemeColorReplacerExtracted theme color css content length: 156143 98% after emitting SizeLimitsPlugin ERROR Failed to compile with 3 errors 17:32:45 error in ./src/pages/mlcs/NewApplication/Mlcs/CompareResult.vue Module Error (from ./node_modules/eslint-loader/index.js): C:\Users\je14902\IdeaProjects\mlcs-web\src\pages\mlcs\NewApplication\Mlcs\CompareResult.vue 117:9 error '<template>' cannot be keyed. Place the key on real elements instead vue/no-template-key 123:15 error Elements in iteration expect to have 'v-bind:key' directives vue/require-v-for-key 126:15 error Elements in iteration expect to have 'v-bind:key' directives vue/require-v-for-key 140:9 error '<template>' cannot be keyed. Place the key on real elements instead vue/no-template-key 145:15 error Elements in iteration expect to have 'v-bind:key' directives vue/require-v-for-key 148:15 error Elements in iteration expect to have 'v-bind:key' directives vue/require-v-for-key 162:9 error '<template>' cannot be keyed. Place the key on real elements instead vue/no-template-key 167:15 error Elements in iteration expect to have 'v-bind:key' directives vue/require-v-for-key 170:15 error Elements in iteration expect to have 'v-bind:key' directives vue/require-v-for-key 184:9 error '<template>' cannot be keyed. Place the key on real elements instead vue/no-template-key 189:15 error Elements in iteration expect to have 'v-bind:key' directives vue/require-v-for-key 192:15 error Elements in iteration expect to have 'v-bind:key' directives vue/require-v-for-key 210:9 error '<template>' cannot be keyed. Place the key on real elements instead vue/no-template-key 215:15 error Elements in iteration expect to have 'v-bind:key' directives vue/require-v-for-key ✖ 14 problems (14 errors, 0 warnings) @ ./src/router/config.js 97:15-71 @ ./src/router/index.js @ ./src/main.js @ multi (webpack)-dev-server/client?http://10.107.112.67:8080&sockPath=/sockjs-node (webpack)/hot/dev-server.js babel-polyfill whatwg-fetch ./src/main.js error in ./src/pages/mlcs/NewApplication/Mlcs/Normal.vue Module Error (from ./node_modules/eslint-loader/index.js): C:\Users\je14902\IdeaProjects\mlcs-web\src\pages\mlcs\NewApplication\Mlcs\Normal.vue 2125:28 error Promise executor functions should not be async no-async-promise-executor ✖ 1 problem (1 error, 0 warnings) @ ./src/router/config.js 67:15-64 @ ./src/router/index.js @ ./src/main.js @ multi (webpack)-dev-server/client?http://10.107.112.67:8080&sockPath=/sockjs-node (webpack)/hot/dev-server.js babel-polyfill whatwg-fetch ./src/main.js error in ./src/pages/mlcs/NewApplication/Mlcs/CompareResult.vue?vue&type=template&id=25a405a5&scoped=true& Module Error (from ./node_modules/vue-loader/lib/loaders/templateLoader.js): (Emitted value instead of an instance of Error) Errors compiling template: <template> cannot be keyed. Place the key on real elements instead. 115| <tbody> 116| <!-- Recipe 不匹配(Photo Area) --> 117| <template v-for="sf in stepForms" :key="'r-' + sf.stepNo"> | ^^^^^^^^^^^^^^^^^^^^^^^ 118| <template v-if="isPhotoArea(sf.area) && sf.stepNo && sf.stepNo.trim()"> 119| <template v-if=" <template> cannot be keyed. Place the key on real elements instead. 138| 139| <!-- Recipe 不匹配(非 Photo Area) --> 140| <template v-for="sf in stepForms" :key="'nr-' + sf.stepNo"> | ^^^^^^^^^^^^^^^^^^^^^^^^ 141| <template v-if="!isPhotoArea(sf.area) && sf.stepNo && sf.stepNo.trim()"> 142| <template v-if=" <template> cannot be keyed. Place the key on real elements instead. 160| 161| <!-- EQP 不匹配 --> 162| <template v-for="sf in stepForms" :key="'eqp-' + sf.stepNo"> | ^^^^^^^^^^^^^^^^^^^^^^^^^ 163| <template v-if="sf.stepNo && sf.stepNo.trim()"> 164| <template v-if=" <template> cannot be keyed. Place the key on real elements instead. 182| 183| <!-- Reticle 不匹配 --> 184| <template v-for="sf in stepForms" :key="'ret-' + sf.stepNo"> | ^^^^^^^^^^^^^^^^^^^^^^^^^ 185| <template v-if="isPhotoArea(sf.area) && sf.stepNo && sf.stepNo.trim()"> 186| <template v-if=" <template> cannot be keyed. Place the key on real elements instead. 208| 209| <!-- Qty 不匹配 --> 210| <template v-for="stepNo in ercAllStep" :key="'qtychk-' + stepNo"> | ^^^^^^^^^^^^^^^^^^^^^^^^^ 211| <template v-if="stepNo && stepNo.trim()"> 212| <template v-if=" @ ./src/pages/mlcs/NewApplication/Mlcs/CompareResult.vue?vue&type=template&id=25a405a5&scoped=true& 1:0-466 1:0-466 @ ./src/pages/mlcs/NewApplication/Mlcs/CompareResult.vue @ ./src/router/config.js @ ./src/router/index.js @ ./src/main.js @ multi (webpack)-dev-server/client?http://10.107.112.67:8080&sockPath=/sockjs-node (webpack)/hot/dev-server.js babel-polyfill whatwg-fetch ./src/main.js
最新发布
12-10
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值