【问题标题】:subscribe is deprecated in Ionicsubscribe 在 Ionic 中已弃用
【发布时间】:2021-04-27 13:35:23
【问题描述】:

我在 Ionic Proyect 中收到此警告“订阅已弃用:使用观察者而不是完整回调”。请帮忙。

fetch(cb) {
    this.loadingIndicator = true;
    this.cservice.postNcRangoConta(this.body).subscribe(
      res => {
        try {
          if (res) {
            this.headers = Object.keys(res[0]);
            this.columns = this.getColumns(this.headers);
            this.temp = [...res];
            cb(res);
            this.loadingIndicator = false;
          }
        } catch (error) {
          this.loadingIndicator = false;
          this.rows = null;
          this.toast.presentToast('No se encontraron datos', 'warning');
        }
      },
      err => {
        console.log(err);
        if (this.desde || this.hasta) {

          this.loadingIndicator = false;
          this.toast.presentToast('La API no responde', 'danger');
        } else {
          this.loadingIndicator = false;
          this.toast.presentToast('Debe llenar las fechas', 'warning');
        }
      }
    );
  }

【问题讨论】:

    标签: javascript ionic-framework rxjs


    【解决方案1】:

    subscribe 方法实际上并未被弃用,但您使用它的方式已被弃用。尝试切换到它的新语法。

    // Deprecated
    source.subscribe(
      (res) => cb(res),
      error => console.error(error),
      () => console.log('Complete')
    );
    
    // Recommended
    source.subscribe({
      next: (res) => cb(res),
      error: error => console.error(error),
      complete: () => console.log('Complete')
    });
    
    
    

    【讨论】:

    • Idk 但仍有突出显示“订阅”字样
    猜你喜欢
    • 1970-01-01
    • 2020-12-21
    • 1970-01-01
    • 2018-06-16
    • 2021-04-30
    • 2020-01-13
    • 1970-01-01
    • 1970-01-01
    • 2022-07-10
    相关资源
    最近更新 更多