我封装了一个批量上传云存储的函数,为什么这里我一用await,就报错:语法错误: Unexpected token, expected ";" (33:22),是怎么回事呢?
代码如下:
<template>
<view><button type="default" @click="myImage">上传</button></view>
</template>
<script>
export default {
data() {
return {};
},
methods: {
async myImage() {
var result = await this.myChooseImage();
var tempFilePaths = result.tempFilePaths;
var result1=this.myUploadFile(tempFilePaths)
console.log(result1)
},
//封装 上传文件
myUploadFile(arr) {
var uploadAll = arr.map(item => {
var extend = /\.\w+$/.exec(item)[0];
var cloudPath = new Date().getTime() + extend;
return uniCloud.uploadFile({
filePath: item,
cloudPath: cloudPath
});
});
var result =await Promise.all(uploadAll);
},
//封装选择函数
myChooseImage() {
return new Promise((resolve, reject) => {
var result = uni.chooseImage({
success(res) {
resolve(res);
},
fail(err) {
reject(err);
}
});
});
}
}
};
</script>
<style></style>
myUploadFile 改为 async myUploadFile