短路逻辑自己并无什么特别好讲的,就讲一个常常会用到的情景吧,与后端联调的时候常常须要判断当某个参数存在时,就把这个参数赋值后端
如app
if (this.userId){ params.append('id',this.userId) }
简单一点应用短路逻辑就能够写成this
this.userId && params.append('userId', this.userId)
新的写法,能够了解下,省的见到这种写法一脸懵逼spa