收藏
回答

api请求过程中,有一个值无法传递成功?

Page({

data: {

text: '',

style: '',

resolution:'',

num:0,

taskId:''

},


onInput1: function (e) {

this.setData({

text: e.detail.value.trim()

})

},


onInput2: function (e) {

this.setData({

style: e.detail.value.trim()

})

},


onInput3: function (e) {

this.setData({

resolution: e.detail.value.trim()

})

},


onInput4: function (e) {

this.setData({

num: parseInt(e.detail.value.trim())||0

})

},


submitData: function () {

var text = this.data.text;

var style = this.data.style;

var resolution = this.data.resolution;

var num = this.data.num;


wx.request({

method: 'POST',

data: {

text: text,

style: style,

resolution:resolution,

num:num

},

header:{

"Content-Type":"application/json"

},

success: function(res) {

if (res.data.error_code !== undefined) {

console.log(res.data.error_msg);

} else {

wx.setStorageSync('taskId', res.data.taskId); //存储taskId到本地

getResult(res.data.taskId); //调用getResult函数并传递参数

}

},

fail: (res) => {

console.log('请求失败');

}

})

},


getResult: function (taskId) {

wx.request({

method: 'POST',

data: {

taskId: taskId //将参数作为taskId传递

},

header:{

"Content-Type":"application/json"

},

success: (res) => {

if (res.data.error_code !== undefined) {

console.log(res.data.error_msg);

} else if (res.data.result.status === 2) {

//结果已生成,显示图片

console.log(res.data.result.image);

} else {

//继续查询结果

getResult(taskId);

}

},

fail: (res) => {

console.log('请求失败');

}

})

},


onClear: function () {

this.setData({

text: '',

style: '',

resolution: '',

num: 0

})

}

})

回答关注问题邀请回答
收藏

1 个回答

  • Demons
    Demons
    2023-04-27

    请具体描述问题出现的流程,并提供能复现问题的简单代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)。

    2023-04-27
    有用
    回复
登录 后发表内容