我想简短一点吗?
function getRedditImg (img) {
if (img === 'default') {
return 'https://i.imgur.com/pMkc6Lo.png'
} else if (img === 'self') {
return 'https://i.imgur.com/pMkc6Lo.png'
}
return img
}
我尝试这样做:
post.thumbnail === ( 'default' || 'self') ? 'https://i.imgur.com/pMkc6Lo.png' : post.thumbnail
但是,它会默认短路真正的...
有什么想法吗?谢谢。
答案 0 :(得分:0)
不要使用开关大小写语法
switch(expression) {
case x:
// code block
break;
case y:
// code block
break;
default:
// code block
}