函数节流的应用场景
间隔一段时间执行一次回调的场景有:
- 滚动加载,加载更多或滚到底部监听
- 谷歌搜索框,搜索联想功能
- 高频点击提交,表单重复提交
-
<el-button type="primary" :loading="isLoading" @click="save">提交</el-button>
-
data() { return { isLoading:false, } },
save() { let _this = this; if(_this.formData.contractorCode){ this.isLoading = true } handAllocation(_this.mostlyGuids,_this.formData.contractorCode).then(res => { if (res.data.success){ this.isLoading = false _this.editShow = false; } }); }
点击提交按钮,把按钮变成loading状态,则不可再重复点击