簡體   English   中英

es6箭頭功能不適用於switch語句

[英]es6 arrow function doesn't work with switch statement

沒有錯誤,但我無法觸發功能。 試圖將我的exec_request函數放在switch語句的上方或下方,但仍然沒有運氣。

exec_request = (url) => {
    alert('test') // not execute here?
}

switch(list_type) {
    case 'temp': {
        const url = `/shops/spaces/${temp}`;
        exec_request(url)
        break;
    }
    default: {
        const url = `/shops/${shop_id}/spaces`;
        exec_request(url)
    }
}

 const list_type = '';//'temp'; const temp = "tmp"; const shop_id = "123"; const exec_request = (url) => { alert(url) // not execute here? } switch(list_type) { case 'temp': { const url = `/shops/spaces/${temp}`; exec_request(url) break; } default: { const url = `/shops/${shop_id}/spaces`; exec_request(url) } } 

您可能需要調用this.exec_request(url)

由於您使用標記了此內容, exec_request不是全局函數。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM