iT邦幫忙

0

在 Vue.js 有個疑問想問一下, 目前有兩層 if 判斷 要怎麼才可以整個跳開 if else 判斷呢?

目前有兩層 if 判斷

當在第二層的 if 判斷 得到錯誤時, 要怎麼才可以跳離整個 if 判斷呢?

if (xhr.data.result[0].smsB_Airlines[0]) {
            let dup = xhr.data.result[0].smsB_Airlines.length - 1;
            if (
              Date.parse(
                xhr.data.result[0].smsB_Airlines[dup].arln_CeaseOP_Date
              ).valueOf() > Date.parse(e.data.arln_BeginOP_Date).valueOf() ||
              !e.data.arln_BeginOP_Date
            ) {
              self.$swal.fire(
                "新增失敗",
                "前代號之停止日期不得大於新增的啟用日",
                "error"
              );
              self.GLOBAL.methods.insUserLog(
                self.GLOBAL.userInfo.user_StaffID,
                "12.15.06.cf",
                "12.15.06",
                "",
                ""
              );
              return;
            } else {
              needData = {
                arln_InsertUserID: self.GLOBAL.userInfo.user_StaffID,
                arln_InsertProgID: "12.15.06",
                arln_Duplicate:
                  Number(xhr.data.result[0].smsB_Airlines.length) + 1,
              };
            }
          } else {
            needData = {
              arln_InsertUserID: self.GLOBAL.userInfo.user_StaffID,
              arln_InsertProgID: "12.15.06",
              arln_Duplicate: 1,
            };
          }

下了 else & return;
都會顯示新增失敗 但是頁面卻還是會出現 資料
只是不會寫進資料庫

要怎麼樣才可以連頁面都不顯示資料呢?

frank575 iT邦新手 4 級 ‧ 2021-08-16 16:18:08 檢舉
這跟 vue 沒關係吧,下個 return 就可以了,會失敗表示你 return 的位置錯了,這部分要看下你是怎麼 return 的了
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 個回答

0
gior__ann
iT邦新手 2 級 ‧ 2021-08-16 16:35:54

感覺是 js 邏輯而已

let typeA = true;
let typeB = false;

function testabc(){
  if(typeA){
    console.log("A success");
    if(typeB){
      console.log("B success");
      return;
    }
  }
}
testabc() // 即使B條件不符還是會印出"A success"


let doublecheck = false;

function testabc2(){
  if(typeA){
    if(typeB){
      doublecheck = true;
    }else{
      doublecheck = false;
    }
  }else{
    doublecheck = false;
  }
  
  if(doublecheck){
    console.log("success")
  }else{
    console.log("error")
  }
}

testabc2() // 需要 條件A 跟 條件B 都符合,才去印 "success"

可能加一個控制器,如果兩個 if 都過了 再去做成功的動作
如果沒過就做失敗的動作 (目前想到的方法是這樣XD)

不知道有沒有符合你的問題~/images/emoticon/emoticon37.gif

我要發表回答

立即登入回答