admin管理员组文章数量:1565801
今天在开发时遇到一个错误(警告)。
问题出现:
想要使用对象中的属性,对el-table表格的label进行判断。
对象数据:
data:[
{
location:'数据1',
...
},
{
location:'数据2',
...
},
]
使用:
<el-table :data="data">
<el-table-column
prop="prop"
:label="
location == '指定值'
? 'label1'
: 'label2'
"
align="center"
/>
</el-table>
运行是正常的,但是控制台发出警告:
`Property "location" was accessed during render but is not defined on instance. `
翻译过来:属性“location”在呈现期间被访问,但没有在实例上定义。
分析原因:
出现这种警告,一般是声明了对象类型的数据,却使用了对象里面的属性直接读取,而不是通过 对象.属性
读取值。
问题解决:
根据理解,在使用属性时应该是通过 对象.属性
读取值,所以应该修改为:
<el-table :data="data">
<el-table-column
prop="prop"
:label="
object.location == '指定值'
? 'label1'
: 'label2'
"
align="center"
/>
</el-table>
本文标签: accessedxxxPropertyinstancedefined
版权声明:本文标题:Property “xxx“ was accessed during render but is not defined on instance. 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://www.elefans.com/dongtai/1726224721a1061368.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论