短路邏輯

簡介

短路邏輯自己並無什麼特別好講的,就講一個常常會用到的情景吧,與後端聯調的時候常常須要判斷當某個參數存在時,就把這個參數賦值後端

app

if (this.userId){
    params.append('id',this.userId)
}

簡單一點應用短路邏輯就能夠寫成this

this.userId && params.append('userId', this.userId)

新的寫法,能夠了解下,省的見到這種寫法一臉懵逼spa

相關文章
相關標籤/搜索