关于我们

质量为本、客户为根、勇于拼搏、务实创新

< 返回新闻公共列表

基于MobX 封装 Action 接口 Loading #85

发布时间:2023-06-27 15:01:00

代码如下


import { action, observable } from 'mobx'; export default class BasicStore {  @observable isLoading = observable.map({ });   @action  changeLoadingStatus (loadingType, type) {  this.isLoading.set(loadingType, type);  } } // 初始化loading export function initLoading(target, key, descriptor) {  const oldValue = descriptor.value;  descriptor.value = async function(...args) {  this.changeLoadingStatus(key, true);  let res;  try {  res = await oldValue.apply(this, args);  } catch (error) {  // 做一些错误上报之类的处理  throw error;  } finally {  this.changeLoadingStatus(key, false);  }  return res;  };   return descriptor; }

/template/Home/leiyu/PC/Static