【发布时间】:2018-09-22 04:01:52
【问题描述】:
我正在尝试从 A 中的函数中的函数访问函数 A,例如:
functionA () {
functionB () {
functionC () {
#want to call functionA from here
}
}
}
这是我正在使用的代码:
updateProgress: function (statusurl){
axios({
method: 'get',
url: statusurl,
dataType: 'json',
headers: {'Content-Type': 'application/json; charset=utf-8'},
async: true,
data: {}
})
.then(function (response) {
var data = response.data
if (data['state'] !== 'PENDING' && data['state'] !== 'PROGRESS') {
if ('result' in data) {
// show result
console.log('result: ' + data['result'])
}
else {
// something unexpected happened
console.log('state: ' + data['state'])
}
}
else {
// rerun in 2 seconds
setTimeout(function() {
this.updateProgress(statusurl)
}, 2000)
}
}.bind(this))
.catch(e => {
console.log('error: ' + e)
})
如您所见,我在 functionC 中使用 this.functionA,在 functionA 上使用 bind()。
我在控制台中收到以下错误:
Uncaught TypeError: this.updateProgress is not a function at eval
你知道怎么做吗?
【问题讨论】:
-
function (response)绑定语法无论如何都是错误的。为什么不直接使用箭头函数,即response =>
标签: javascript vue.js vuejs2 axios