Property “xxx“ was accessed during render but is not defined on instance.

今天在开发时遇到一个错误(警告)。

问题出现:

想要使用对象中的属性,对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>

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值