可能会这么写

<a-table>  <span v-for="(item, index) in header" :key="index" :slot="item.dataIndex" slot-scope="text">    {{ text }}  </span></a-table>

然而这样子会报错,因为v-for和slot-scope在同一级

报错信息:Ambiguous combined usage of slot-scope and v-for on (v-for takes higher priority). Use a wrapper <template> for the scoped slot to make it clearer.

提醒在外边包一层< template >,于是可能改成上面这样,然而也会报错

<a-table>  <template v-for="(item, index) in header" :key="index">    <span :slot="item.dataIndex" slot-scope="text">      {{ text }}    </span>  </template></a-table>
报错信息:<template> cannot be keyed. Place the key on real elements instead.

提醒< template >template不能写key, 即便没有这个错,表格数据也不会渲染进去,因为这一层没有slot,应该说slot应该是放最里面,同时把:key放外面


改成如下

<a-table>  <template v-for="(item, index) in header" :slot="item.dataIndex" slot-scope="text">    <span :key="index">      {{ text }}    </span>  </template></a-table>

以上解决问题

原文:https://blog.csdn.net/Cookysurongbin/article/details/101310442