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你的答案对我来说很有用,而且是最简单的,谢谢!