Vue.js Vue启动请求一个接一个

Vue.js Vue启动请求一个接一个,vue.js,vue-resource,Vue.js,Vue Resource,我有两个功能。我想启动一个函数-等待firstFunction()结束,然后启动secondFunction()。但是我不想把这当作一个回调 firstFunction() { this.$http.post( `url1`, data1, { channel: 'default' }, { headers: { 'Content-Type': 'application/x-www-form-ur

我有两个功能。我想启动一个函数-等待
firstFunction()
结束,然后启动
secondFunction()
。但是我不想把这当作一个回调

firstFunction() {
        this.$http.post(
          `url1`,
            data1,
          { channel: 'default' },
          { headers: { 'Content-Type': 'application/x-www-form-urlencoded' } }
        ).then(response => {
            console.log(response)
        });
},
secondFunction() {
       this.$http.post(
          `url2`,
            data2,
          { channel: 'default' },
          { headers: { 'Content-Type': 'application/x-www-form-urlencoded' } }
        ).then(response => {
            console.log(response)
        });
},
finalFunction() {
    this.firstFunction() 
    this.secondFunction()
}

firstFunction
中返回http post调用:
返回此。$http.post(…
。这将返回
Promise
,因此您可以在
finalFunction
中执行此操作:
this.firstFunction()。然后(()=>this.secondFunction())
也许你需要的是@thanksd你的答案对我来说很有用,而且是最简单的,谢谢!