javascript - 如何在catch上终止函数执行?

标签 javascript vue.js axios

如何在 catch 上终止函数执行?我认为 return 应该放在我放置的位置 (.catch( error => {console.log(error);} return)),但这不起作用。告诉我怎样做才是正确的?

    getCustomers: function () {
            let url = '/crm/customer/';

            axios.get(url).then((response) => {
                this.customers = response.data.results;
                if (this.customers.length === 100) {
                    for (let i = 2; i < 100; i++) {
                        axios.get('/crm/customer/?page=' + i).then((response) => {
                            this.c = response.data.results;
                            for (let item of this.c.values()) {
                                this.customers.push(item);
                            }
                        }).catch( global_waiting_stop());

                    }
                }
            }).catch( error => { console.log(error); })
            .finally(() => (global_waiting_stop()));
        },

最佳答案

finally() then之后执行和 catch功能。如果您不想让它运行,请移动您的 global_waiting_stop到底部then相反,阻止并摆脱 finally .

getCustomers: function() {
  let url = '/crm/customer/';
  axios.get(url).then((response) => {
    this.customers = response.data.results;
    if (this.customers.length === 100) {
      for (let i = 2; i < 100; i++) {
        axios.get('/crm/customer/?page=' + i).then((response) => {
            this.c = response.data.results;
            for (let item of this.c.values()) {
              this.customers.push(item);
            }
          }).catch(error => {
              console.log(error);
            }
            return)
          .finally(() => (global_waiting_stop()));
      }
    }
    global_waiting_stop();
  }).catch(error => {
    console.log(error);
  })
},

关于javascript - 如何在catch上终止函数执行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63634333/

相关文章:

javascript - 如何使用类访问数组中的某个索引?

javascript - vue.js中如何加载scss

vue.js - 如何直接在 VueX 状态下设置值

javascript - 如何在 Vue 中将 v-for 索引传递给子级?

javascript - 哪些手机浏览器支持ES6?

javascript - ASP :new listview javascript question

javascript - 根据时间值更改文本颜色php

typescript - axios查询参数?

javascript - UncaughtTypeError products.map 不是函数

javascript - onclick 当ajax响应到达时准备html并在react中渲染?