<分区>
在 Vue 组件中:
import { someRequestMethod } from '@/api/requ'
...
methods: {
testMethod() {
someRequestMethod(someRequestData).then(function() {
this.outMethod_01()
}).then(function() {
this.outMethod_02()
})
}
outMethod_01() {
console.log('I am an outer method 01.');
}
outMethod_02() {
console.log('I am an outer method 02.');
}
}
当我用 Promise
响应调用 testMethod
时。
然后我想在成功时调用 outMethod_01
,在出错时调用 outMethod_02
。
但我得到错误 outMethod_01 is undefined
和 outMethod_02 is undefined
。
那么如何在Promise
中调用外部方法呢?