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

fix: 部分页面回调改为箭头函数方式

上级 56ec9a7b
<template> <template>
<!-- #ifdef APP --> <!-- #ifdef APP -->
<scroll-view style="flex: 1"> <scroll-view style="flex: 1">
<!-- #endif --> <!-- #endif -->
<view> <view>
<page-head :title="title"></page-head> <page-head :title="title"></page-head>
<view class="uni-padding-wrap uni-common-mt"> <view class="uni-padding-wrap uni-common-mt">
...@@ -16,85 +16,85 @@ ...@@ -16,85 +16,85 @@
</view> </view>
</view> </view>
</view> </view>
<!-- #ifdef APP --> <!-- #ifdef APP -->
</scroll-view> </scroll-view>
<!-- #endif --> <!-- #endif -->
</template> </template>
<script> <script>
export default { export default {
data() { data() {
return { return {
title: 'downloadFile', title: 'downloadFile',
imageSrc: '', imageSrc: '',
task: null as DownloadTask | null, task: null as DownloadTask | null,
pageVisible: false, pageVisible: false,
//自动化测试例专用 //自动化测试例专用
jest_result: false jest_result: false
} }
}, },
onLoad() { onLoad() {
this.pageVisible = true; this.pageVisible = true;
}, },
onUnload() { onUnload() {
this.imageSrc = ''; this.imageSrc = '';
this.pageVisible = false; this.pageVisible = false;
uni.hideLoading(); uni.hideLoading();
this.task?.abort(); this.task?.abort();
}, },
methods: { methods: {
downloadImage: function() { downloadImage: function () {
uni.showLoading({ uni.showLoading({
title: '下载中' title: '下载中'
}) })
var self = this var self = this
this.task = uni.downloadFile({ this.task = uni.downloadFile({
url: "https://web-assets.dcloud.net.cn/unidoc/zh/uni-app.png", url: "https://web-assets.dcloud.net.cn/unidoc/zh/uni-app.png",
success(res) { success: (res) => {
if (this.pageVisible) { if (this.pageVisible) {
console.log('downloadFile success, res is', res) console.log('downloadFile success, res is', res)
self.imageSrc = res.tempFilePath; self.imageSrc = res.tempFilePath;
uni.hideLoading(); uni.hideLoading();
} }
}, },
fail: (err) => { fail: (err) => {
if (this.pageVisible) { if (this.pageVisible) {
console.log('downloadFile fail, err is:', err) console.log('downloadFile fail, err is:', err)
uni.hideLoading(); uni.hideLoading();
} }
} }
}); });
this.task?.onProgressUpdate((update) => { this.task?.onProgressUpdate((update) => {
if (this.pageVisible) { if (this.pageVisible) {
console.log("progress : ", update.progress); console.log("progress : ", update.progress);
} }
}) })
}, },
//自动化测试例专用 //自动化测试例专用
jest_downloadFile(){ jest_downloadFile() {
uni.downloadFile({ uni.downloadFile({
url: "https://web-assets.dcloud.net.cn/unidoc/zh/uni-app.png", url: "https://web-assets.dcloud.net.cn/unidoc/zh/uni-app.png",
success() { success: () => {
this.jest_result = true this.jest_result = true
}, },
fail: () => { fail: () => {
this.jest_result = false this.jest_result = false
} }
}); });
}
} }
} }
}
</script> </script>
<style> <style>
.img { .img {
width: 500rpx; width: 500rpx;
height: 500rpx; height: 500rpx;
margin: 0 auto; margin: 0 auto;
} }
.image-container { .image-container {
display: flex; display: flex;
justify-content: center; justify-content: center;
align-items: center; align-items: center;
} }
</style> </style>
\ No newline at end of file
...@@ -190,7 +190,7 @@ ...@@ -190,7 +190,7 @@
sslVerify: false, sslVerify: false,
withCredentials: false, withCredentials: false,
firstIpv4: false, firstIpv4: false,
success(res) { success: (res) => {
if (this.pageVisible) { if (this.pageVisible) {
console.log('request success', JSON.stringify(res.data)) console.log('request success', JSON.stringify(res.data))
uni.showToast({ uni.showToast({
...@@ -202,7 +202,7 @@ ...@@ -202,7 +202,7 @@
this.res = '请求结果 : ' + JSON.stringify(res); this.res = '请求结果 : ' + JSON.stringify(res);
} }
}, },
fail(err) { fail: (err) => {
if (this.pageVisible) { if (this.pageVisible) {
console.log('request fail', err); console.log('request fail', err);
uni.showModal({ uni.showModal({
...@@ -211,7 +211,7 @@ ...@@ -211,7 +211,7 @@
}); });
} }
}, },
complete() { complete: () => {
uni.hideLoading() uni.hideLoading()
}, },
}); });
...@@ -229,14 +229,14 @@ ...@@ -229,14 +229,14 @@
sslVerify: false, sslVerify: false,
withCredentials: false, withCredentials: false,
firstIpv4: false, firstIpv4: false,
success() { success: () => {
this.jest_result = true; this.jest_result = true;
}, },
fail() { fail: () => {
this.jest_result = false; this.jest_result = false;
}, },
}); });
} }
} }
} }
</script> </script>
\ No newline at end of file
...@@ -60,10 +60,10 @@ export default { ...@@ -60,10 +60,10 @@ export default {
uni.closeSocket({ uni.closeSocket({
code: 1000, code: 1000,
reason: 'close reason from client', reason: 'close reason from client',
success(res: any) { success:(res: any) => {
console.log('uni.closeSocket success', res) console.log('uni.closeSocket success', res)
}, },
fail(err: any) { fail:(err: any) => {
console.log('uni.closeSocket fail', err) console.log('uni.closeSocket fail', err)
}, },
} as CloseSocketOptions) } as CloseSocketOptions)
...@@ -84,11 +84,11 @@ export default { ...@@ -84,11 +84,11 @@ export default {
}) })
uni.connectSocket({ uni.connectSocket({
url: 'ws://websocket.dcloud.net.cn', url: 'ws://websocket.dcloud.net.cn',
success(res: any) { success:(res: any) => {
// 这里是接口调用成功的回调,不是连接成功的回调,请注意 // 这里是接口调用成功的回调,不是连接成功的回调,请注意
console.log('uni.connectSocket success', res) console.log('uni.connectSocket success', res)
}, },
fail(err: any) { fail:(err: any) => {
// 这里是接口调用失败的回调,不是连接失败的回调,请注意 // 这里是接口调用失败的回调,不是连接失败的回调,请注意
console.log('uni.connectSocket fail', err) console.log('uni.connectSocket fail', err)
}, },
...@@ -140,10 +140,10 @@ export default { ...@@ -140,10 +140,10 @@ export default {
this.platform + this.platform +
' : ' + ' : ' +
parseInt((Math.random() * 10000).toString()).toString(), parseInt((Math.random() * 10000).toString()).toString(),
success(res: any) { success:(res: any) => {
console.log(res) console.log(res)
}, },
fail(err: any) { fail:(err: any) => {
console.log(err) console.log(err)
}, },
} as SendSocketMessageOptions) } as SendSocketMessageOptions)
...@@ -152,10 +152,10 @@ export default { ...@@ -152,10 +152,10 @@ export default {
uni.closeSocket({ uni.closeSocket({
code: 1000, code: 1000,
reason: 'close reason from client', reason: 'close reason from client',
success(res: any) { success:(res: any) => {
console.log('uni.closeSocket success', res) console.log('uni.closeSocket success', res)
}, },
fail(err: any) { fail:(err: any) => {
console.log('uni.closeSocket fail', err) console.log('uni.closeSocket fail', err)
}, },
} as CloseSocketOptions) } as CloseSocketOptions)
......
...@@ -65,10 +65,10 @@ export default { ...@@ -65,10 +65,10 @@ export default {
task.close({ task.close({
code: 1000, code: 1000,
reason: 'close reason from client', reason: 'close reason from client',
success(res: any) { success:(res: any) => {
console.log('uni.closeSocket success', res) console.log('uni.closeSocket success', res)
}, },
fail(err: any) { fail:(err: any) =>{
console.log('uni.closeSocket fail', err) console.log('uni.closeSocket fail', err)
}, },
} as CloseSocketOptions) } as CloseSocketOptions)
...@@ -89,11 +89,11 @@ export default { ...@@ -89,11 +89,11 @@ export default {
}) })
this.socketTask = uni.connectSocket({ this.socketTask = uni.connectSocket({
url: 'ws://websocket.dcloud.net.cn', url: 'ws://websocket.dcloud.net.cn',
success(res: any) { success:(res: any) =>{
// 这里是接口调用成功的回调,不是连接成功的回调,请注意 // 这里是接口调用成功的回调,不是连接成功的回调,请注意
console.log('uni.connectSocket success', res) console.log('uni.connectSocket success', res)
}, },
fail(err: any) { fail:(err: any) =>{
// 这里是接口调用失败的回调,不是连接失败的回调,请注意 // 这里是接口调用失败的回调,不是连接失败的回调,请注意
console.log('uni.connectSocket fail', err) console.log('uni.connectSocket fail', err)
}, },
...@@ -145,10 +145,10 @@ export default { ...@@ -145,10 +145,10 @@ export default {
parseInt(Math.random() * 10000 + '').toString() parseInt(Math.random() * 10000 + '').toString()
this.socketTask?.send({ this.socketTask?.send({
data, data,
success(res: any) { success:(res: any) =>{
console.log(res) console.log(res)
}, },
fail(err: any) { fail:(err: any) =>{
console.log(err) console.log(err)
}, },
} as SendSocketMessageOptions) } as SendSocketMessageOptions)
...@@ -157,10 +157,10 @@ export default { ...@@ -157,10 +157,10 @@ export default {
this.socketTask?.close({ this.socketTask?.close({
code: 1000, code: 1000,
reason: 'close reason from client', reason: 'close reason from client',
success(res: any) { success:(res: any) =>{
console.log('uni.closeSocket success', res) console.log('uni.closeSocket success', res)
}, },
fail(err: any) { fail:(err: any) =>{
console.log('uni.closeSocket fail', err) console.log('uni.closeSocket fail', err)
}, },
} as CloseSocketOptions) } as CloseSocketOptions)
...@@ -184,10 +184,10 @@ export default { ...@@ -184,10 +184,10 @@ export default {
parseInt(Math.random() * 10000 + '').toString() parseInt(Math.random() * 10000 + '').toString()
this.socketTask?.send({ this.socketTask?.send({
data, data,
success(_) { success:(_) =>{
this.jest_result++ this.jest_result++
}, },
fail(_) { fail:(_) =>{
this.jest_result = 0 this.jest_result = 0
}, },
} as SendSocketMessageOptions) } as SendSocketMessageOptions)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册