我正在使用Vue JS,并试图使用三元表达式有条件地更改某物的值,我很难将以下内容转换为三元表达式,默认情况下,这是我的方法:isLoading为true
fetchData(showLoading) {
if (showLoading) {
this.isLoading = true
} else {
this.isLoading = false
}
}发布于 2019-06-17 11:00:07
这里不要使用条件运算符,只要将showLoading分配给isLoading,假设您传递的是一个布尔值:
this.isLoading = showLoading;如果不一定要传递布尔值,那么先转换为布尔值(如果需要的话):
this.isLoading = Boolean(showLoading);如果必须使用条件运算符,则如下所示:
this.isLoading = showLoading ? true : false;发布于 2020-10-17 18:13:01
fetchData(showLoading) {
showLoading ? (this.isLoading = true) : (this.isLoading = false)
}发布于 2019-08-28 06:01:53
您的“showLoading”数据是我猜布尔的,如果没有其他的话,您就不需要了。
this.isLoading = showLoading它是错误的,下面的代码将得到错误
this.isLoading = showLoading ? true : false; https://stackoverflow.com/questions/56629915
复制相似问题