v-for and slot-scoped报错问题
文章目录
可能会这么写
<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

评论
登录后参与技术讨论,分享你的经验与见解。
登录 / 注册暂无评论