可以将代码优化为使用switch语句,同时使用默认情况来处理其他情况:

switch(index){ case 0: this.legendShow = false; this.topCardShow = true; break; case 1: this.legendShow = true; this.topCardShow = false; break; default: this.legendShow = false; this.topCardShow = false; break; }

这样可以使代码更加简洁和易读。

ifinidex == 0 thislegendShow = false; thistopCardShow = true;else ifindex == 1 thislegendShow = true; thistopCardShow = false;else ifindex == 2 thislegendShow = false; thistopCardShow = false;以上