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

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

上级 56ec9a7b
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
<!-- #endif --> <!-- #endif -->
</template> </template>
<script> <script>
export default { export default {
data() { data() {
return { return {
title: 'downloadFile', title: 'downloadFile',
...@@ -42,14 +42,14 @@ export default { ...@@ -42,14 +42,14 @@ export default {
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;
...@@ -70,10 +70,10 @@ export default { ...@@ -70,10 +70,10 @@ export default {
}) })
}, },
//自动化测试例专用 //自动化测试例专用
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: () => {
...@@ -82,19 +82,19 @@ export default { ...@@ -82,19 +82,19 @@ export default {
}); });
} }
} }
} }
</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,10 +229,10 @@ ...@@ -229,10 +229,10 @@
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;
}, },
}); });
......
...@@ -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.
先完成此消息的编辑!
想要评论请 注册