upload: function () { let that = this; let {uploadFlag} = that.data; if (that.data.uploadFlag) { return; } that.data.uploadFlag = true; //上傳錄製的音頻 wx.uploadFile({ url: '', filePath: that.data.link, name: 'file', formData: { userInfo: that.data.userInfo, ... }, header: { 'content-type': 'multipart/form-data' }, success: function (res) { console.log('dd',res.statusCode) if (res.statusCode === 200){ //todo }else{ that.data.uploadFlag = false; } }, fail: function (err) { that.data.uploadFlag = false; } }) },
以上就是一個upload函數中利用wx.uploadFile上傳音頻文件,就是設置個uploadFlag做爲標記,經過狀態的改變決定是否能請求apiapi