當使用for循環動態渲染表頭時,表格視圖不更新。經檢查發現,key值原先綁定的是索引,即 :key="i",導致 item.prop改變后視圖更新錯亂,key值更改后 :key="item.prop",問題得到解決
<template v-for="(item, i) in tableColumn"> <vxe-table-column width="160" :key="item.prop" v-if="i === 0" :field="item.prop" :title="item.desc"></vxe-table-column> <vxe-table-column :key="item.prop" v-else :field="item.prop" :title="item.desc"></vxe-table-column> </template>