Property “xxx“ was accessed during render but is not defined on instance.
属性“location”在呈现期间被访问,但没有在实例上定义。
文章共358字 · 阅读需要大约2分钟
一键AI生成摘要,助你高效阅读
问答
·
今天在开发时遇到一个错误(警告)。
问题出现:
想要使用对象中的属性,对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>
更多推荐
已为社区贡献1条内容
所有评论(0)