如何解决如何访问和读取接口对象上的属性
代码 section_1
中的方法在父组件中,当我在浏览器控制台的 measurementCoordinates
中显示接收到的事件的内容时:
onMeasurementCoordinatesReceived:-> [object Object]
但是当我尝试访问接收到的事件的任何属性时,我收到 undefined
。
请告诉我如何访问和读取接口对象上的属性
代码:
onMeasurementCoordinatesReceived(measurementCoordinates: ICoordinates) {
console.log("onMeasurementCoordinatesReceived:-> " + measurementCoordinates);
}
chils 组件中的接口
export interface ICoordinates {
originLng: number;
originLat: number;
destinationLng: number;
destinationLat: number;
}
解决方法
首先,您可以使用 "," 而不是 "+" 来控制台.记录字符串 + 对象,例如:
console.log("string",object)
否则js会使用默认的toString "[object Object]"
您可以像访问任何其他对象一样访问属性,就像:
objectName.propertyName
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。