在移动端component要切来切去的,下面这样写感觉很乱,
想知道有没有更优雅的处理方式?
detailShow = false;
contactShow = false;
searchShow = false;
homeShow = true;
goBackHome() {
this.detailShow = false;
this.contactShow = false;
this.searchShow = false;
this.homeShow = true;
}
goContact() {
this.homeShow = false;
this.detailShow = false;
this.searchShow = false;
this.contact = true;
}
goSearch() {
this.homeShow = false;
this.detailShow = false;
this.contactShow = false;
this.searchShow = true;
}
用一个字符串变量 showPage 控制显示
this.showPage === 'home' 时显示home页面
this.showPage === 'detail' 时显示detail页面
以此类推
跳转方法也是写一个就好了