原因:
不支持在<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>
文章讲述了在Vue.js中不能在<template>元素上直接绑定属性,如:key,提供了一个替代方案,即使用<div>元素进行v-for循环并绑定key属性,以实现动态渲染表格列的效果。


1347

被折叠的 条评论
为什么被折叠?



