Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
284 views
in Technique[技术] by (71.8m points)

javascript - 尝试使用Vue JS POST等待setInterval(Trying to await setInterval with Vue JS POST)

I'm trying to test the realistic performance of memory and CPU load on a server by making POST requests and recieving a response within a setInterval() function.

(我正在尝试通过发出POST请求并在setInterval()函数中接收响应来测试服务器上内存和CPU负载的实际性能。)

The issue is, my function will always run regardless of whether a successful response is given, I'd like to be able to pause the function until the .then() function comes back with a response, and then resume my interval, I've got the following in the mounted() hook in my Vue JS project:

(问题是,无论是否给出成功的响应,我的函数将始终运行,我希望能够暂停该函数,直到.then()函数返回响应,然后恢复我的间隔,在我的Vue JS项目的mounted()挂钩中有以下内容:)

mounted () {

  setInterval(() => {
    this.$http.post('http://example.com/api', {
      apiKey: this.formData.one,
      application: this.formData.two
    }, {
      emulateJSON: true,
      headers: {
        'Content-Type': 'multipart/form-data'
      }
    }).then(function (response) {
      console.log('Success')
    }).catch(function (err) {
      console.log('Error')
    }).bind(this)
  }, 500)

}
  ask by Ryan Holton translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...