Web前端
使用setTimeout以及async await的误区
我们平时在遇到很多比较怪异的事情的时候,我们会使用setTimeout这样的奇淫异技,比如避免执行的太快了,某些数据还没有来等,我之前基本不用这个,但是在最近的一个项目中用到了。 项目大致是这样的,用的element-ui的el-upload来实现图片上传,就是一个弹框,里面有很多tab页,每个tab也都有el-upload,只是能每个上传的参数和地址什么的是不同的。 <div>操作类型</div> <el-radio v-model="currentSelect" v-for="(item, index) in configs" :label="index" :key="'operateRadio' + index" >{{ item.label }} </el-radio> <el-upload :data="data" :action="url" :auto-upload="false" ref="elUpload"> <el-button type="primary" size="small" @click="submit">上传文件</el-button> </el-upload> props:[''configs"] data(){ data: "", url: "", currentSelect: 0, }, computed: { config() { return this.configs[this.currentSelect] || {}; }, }, methods: { submit(){ this.data Read more…