如何从onreadystatechange
调用我的某个组件功能(因为它不能将this
识别为我的班级,而是识别为xmlhttpelement
)
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState == 4) {
if (xmlhttp.status == 200) {
this.anotherFunction(xmlhttp); //this is considered as xmlhttp instead of my class which contains this function
}
}
答案 0 :(得分:6)
改为使用箭头功能:
xmlhttp.onreadystatechange = () => {
...
}
这种方式this
将引用组件实例