TheNorthMemory / whats-alipay

支付宝 Alipay OpenAPI SDK
MIT License
15 stars 2 forks source link

Decorator.defaults.method配置项无法正确应用到实例参数上 #1

Closed TheNorthMemory closed 3 years ago

TheNorthMemory commented 3 years ago

refer to axios/axios#2844, 0.20.0

It was designed by purpose and there are some test cases to ensure that. valueFromConfig2Keys means keys that will not be inherited from defaults. See axios/axios#1395 (comment). And params has been changed in axios/axios#2656.

url, method,data 三个参数始终来自实例参数,mergeConfig 方法无法合并(会丢失),Decorator.constructor 不能依赖此方法。

TheNorthMemory commented 3 years ago

project specifical configuration merging with the following method:

  /**
   * Deep merge the input with the defaults
   *
   * @param {object} config - The configuration.
   *
   * @returns {object} - With the built-in configuration.
   */
  static withDefaults(config = {}) {
    const defaults = {...this.defaults}

    config.headers = {...defaults.headers, ...config.headers}
    config.params = {...defaults.params, ...config.params}
    config = {...defaults, ...config}

    return config
  }