如何在 ionic 3 中禁用视图缓存



我们将ionic 3与d3js一起使用。我们在每个组件中都有很多 d3.js 转换(我们认为这需要大量内存(。 应用程序最初对导航和内容呈现的响应速度很快(快速(,但是在导航 5-10 个页面后,应用程序会变慢。我们看到页面导航和内容呈现的滞后。 我们认为这是因为标志性 3 中的视图缓存(不确定是否在标志性 3 中启用了视图缓存(。

当用户单击导航按钮时,我们会从导航控制器中推送或弹出。 有没有办法禁用视图缓存,以便无论用户在视图之间导航多少次,应用程序性能都相同?

"@ionic/应用程序脚本": "3.1.9", "@ionic原生/核心": "4.7.0",

主页和图形页之间的示例代码。

@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
constructor(public navCtrl: NavController) {
console.log('construct again');
}
showMigrationChart() {
this.navCtrl.push(MigrationChart);
}
showColumnChart() {
this.navCtrl.push(ColumnChart);
}
}

@Component({
selector: 'migration-chart',
templateUrl: '../../common/chart.html'
})
export class MigrationChart implements OnInit {
@ViewChild('appChart') private chartContainer: ElementRef;
public chartName = 'Column Chart';
constructor(public navCtrl: NavController) {
console.log('MigrationChart construct again');
}
ngOnInit() {
this.chartName = migrationEngine(this.chartContainer.nativeElement);
}
public onBackClick() {
console.log('getViews length= '+ this.navCtrl.length());
console.log('getViews = ', this.navCtrl.getViews());
this.navCtrl.pop();
}
}

Ionic 框架没有问题。 在关闭页面/组件时,没有正确清理javascript计时器和while循环,这导致应用程序变慢。 我们更改了代码以在ngOnDestroy中进行清理,现在一切正常。

最新更新