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

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

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