Hello: function(username, onSuccess)
{
//console.log('hello '+username)
wx.request({
url: 'https://gzhwedu.cn:5001/api/test/hello/'+username,
data: {
},
header: {
'content-type': 'application/json' // 默认值
},
success (res) {
console.log(res.data)
onSuccess(res.data)
}
})
},
getHello: function(username, onSuccess) {
return new Promise((resolve, reject) => {
this.Hello(username,
(d) => {resolve(d)}
)
})
},
onTest: function(){
//this.test((msg) => console.log(msg))
this.getHello('user1', (res)=>console.log(res))
.then( (result) => this.getHello(result + ',user2', (res)=>console.log(res)))
.then( (result) => this.getHello(result + ',user3', (res)=>console.log(res)))
}
涉及技术:
Promise、参数和返回值传递