_request() {
uni.request({
url: this.websiteUrl + `${stringListApi}`,
method: 'POST',
dataType: 'json',
data: {},
success: res => {
this.stringList = res.data.data;
console.log(this.stringList);
},
fail: err => {
console.log(err);
},
complete: () => {}
});
},
_requestPromise() {
uni.request({
url: this.websiteUrl + `${stringListApi}`,
method: 'POST',
dataType: 'json',
data: { token: this.$store.state.token }
})
.then(res => {
this.stringList = res[1].data.data;
console.log(this.stringList);
})
.catch(err => {
console.log(err);
});
},
async _requestAwait() {
const [err, res] = await uni.request({
url: this.websiteUrl + `${stringListApi}`,
method: 'POST',
dataType: 'json',
data: {}
});
if (err) {
console.log(err);
} else {
this.stringList = res.data.data;
console.log(this.stringList);
}
}
uniapp三种请求方法示例
最新推荐文章于 2025-08-31 02:30:16 发布
本文详细介绍了uni-app中使用request进行网络请求的三种方法:回调函数、Promise和async/await。通过具体代码示例,展示了如何配置请求参数,如URL、方法、数据类型等,并处理响应结果。
2945

被折叠的 条评论
为什么被折叠?



