提交 1161b07a 编写于 作者: taohebin@dcloud.io's avatar taohebin@dcloud.io

update: 网络请求示例 增加请求完毕task置空

上级 608bae4d
...@@ -55,11 +55,13 @@ ...@@ -55,11 +55,13 @@
success: (res) => { success: (res) => {
console.log('downloadFile success, res is', res.tempFilePath) console.log('downloadFile success, res is', res.tempFilePath)
self.imageSrc = res.tempFilePath; self.imageSrc = res.tempFilePath;
uni.hideLoading();
}, },
fail: (err) => { fail: (err) => {
console.log('downloadFile fail, err is:', err) console.log('downloadFile fail, err is:', err)
uni.hideLoading(); },
complete: (res) => {
uni.hideLoading();
this.task = null;
} }
}); });
this.task?.onProgressUpdate((update) => { this.task?.onProgressUpdate((update) => {
......
...@@ -218,7 +218,8 @@ ...@@ -218,7 +218,8 @@
}); });
}, },
complete: () => { complete: () => {
uni.hideLoading() uni.hideLoading()
this.task = null
}, },
}); });
}, },
......
...@@ -61,7 +61,6 @@ ...@@ -61,7 +61,6 @@
}, },
success: (res) => { success: (res) => {
console.log('uploadImage success, res is:', res) console.log('uploadImage success, res is:', res)
uni.hideLoading();
uni.showToast({ uni.showToast({
title: '上传成功', title: '上传成功',
icon: 'success', icon: 'success',
...@@ -71,12 +70,15 @@ ...@@ -71,12 +70,15 @@
}, },
fail: (err) => { fail: (err) => {
console.log('uploadImage fail', err); console.log('uploadImage fail', err);
uni.hideLoading();
uni.showModal({ uni.showModal({
content: err.errMsg, content: err.errMsg,
showCancel: false showCancel: false
}); });
}, },
complete: (res) => {
uni.hideLoading();
this.task = null
}
}); });
}, },
fail: (err) => { fail: (err) => {
...@@ -87,7 +89,7 @@ ...@@ -87,7 +89,7 @@
//自动化测试例专用 //自动化测试例专用
jest_uploadFile() { jest_uploadFile() {
const imageSrc = "/static/uni.png"; const imageSrc = "/static/uni.png";
this.task = uni.uploadFile({ uni.uploadFile({
url: 'https://unidemo.dcloud.net.cn/upload', //仅为示例,非真实的接口地址 url: 'https://unidemo.dcloud.net.cn/upload', //仅为示例,非真实的接口地址
filePath: imageSrc, filePath: imageSrc,
name: 'file', name: 'file',
...@@ -160,7 +162,7 @@ ...@@ -160,7 +162,7 @@
}, },
jest_cookie_upload(needCookie : boolean) { jest_cookie_upload(needCookie : boolean) {
const imageSrc = "/static/uni.png"; const imageSrc = "/static/uni.png";
this.task = uni.uploadFile({ uni.uploadFile({
url: 'https://request.dcloud.net.cn/api/http/header/upload', url: 'https://request.dcloud.net.cn/api/http/header/upload',
filePath: imageSrc, filePath: imageSrc,
name: 'file', name: 'file',
...@@ -180,7 +182,7 @@ ...@@ -180,7 +182,7 @@
}, },
jest_files_upload() { jest_files_upload() {
const imageSrc = "/static/uni.png"; const imageSrc = "/static/uni.png";
this.task = uni.uploadFile({ uni.uploadFile({
url: 'https://unidemo.dcloud.net.cn/upload', url: 'https://unidemo.dcloud.net.cn/upload',
files: [ files: [
{ {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册