1024啦

祝 CSDN 和 自己 明天更美好吧!

虽然没有程序员鼓励师小姐姐的说....

在微信小程序中,下面这段代码存在以下问题: 1. `const status = await _.imgSecCheck(tempFilePath)` 语句中没有使用 `async` 函数,无法使用 `await` 关键字,应该将该函数改为 `async` 函数。 2. `await` 关键字只能在 `async` 函数中使用,因此需要将 `success` 回调函数改为 `async` 函数。 3. `success` 回调函数中的 `_.setState` 函数在微信小程序中应该使用 `this.setData` 函数进行替换。 4. `Taro.getImageInfo` 函数在微信小程序中应该使用 `wx.getImageInfo` 函数进行替换。 下面是修复后的代码: ``` addPic: function () { const _ = this; const { quality } = this.state Taro.chooseImage({ count: 1, sizeType: ['original', 'compressed'], sourceType: ['album'], success: async function(result) { const tempFilePath = result.tempFilePaths[0]; let size = result.tempFiles[0].size; if (size > 1024 * 1024 * 8) { //大于8M返回 return Taro.showToast({ title: '图片大于8M啦', icon: 'none' }) } if (size < 1024 * 800) { //小于800kb压缩 const status = await _.imgSecCheck(tempFilePath) if (status == true) { console.log('通过了处理'); //走检测通过处理 } } else { wx.getImageInfo({ src: tempFilePath, success: async function(res) { _.setData({ //设置原始宽高 cWidth: res.width, cHeight: res.height }) try { const imagePath = await _.getCanvasImg(tempFilePath, res.width, res.height, quality); const status = await _.imgSecCheck(imagePath) if (status == true) { console.log('通过了处理'); //走检测通过处理 } } catch (error) { } } }) } } }) }, ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值