[Vuejs]-How to use if else before .then() .catch() in Vue.js?

3👍

Try in the following way.

editTool() {
    return ToolService.editTool(this.id, this.editedItem)
  },

  newTool() {
    return ToolService.addTool(this.editedItem)
  },

  newMethod() {
    let method = this.newTool;
    if (this.edit) method = this.editTool;
    return method().then((response) => {
        this.$refs.dialogInfo.setSuccess(response);
      })
      .catch((error) => {
        this.$refs.dialogInfo.setError(error);
      })
      .finally(() => {
        this.$emit("completed");
      });
  }

Leave a comment