简体   繁体   English

在Ionic3中在后台加载页面

[英]Load page in background in Ionic3

I'm using the tab template in my Ionic3 app, with 3 pages, all of them with images. 我在Ionic3应用程序中使用选项卡模板,共有3个页面,所有页面均带有图像。 When the application loads, the HomePage renders normally with images and no delay. 当应用程序加载时, HomePage正常呈现图像且没有延迟。 However, when I try to open the other pages for the first time, there is a considerable amount of time between opening the page and image loading. 但是,当我第一次尝试打开其他页面时,在打开页面和加载图像之间有相当长的时间。 Once the page is loaded, this doesn't happen anymore. 页面加载后,就不会再发生这种情况。

All images are loaded inside cards as followed: 所有图像均按如下方式装入卡中:

<ion-card>
    <img src="assets/prettyimg.png"/>
    <div class="card-title">Pretty!</div>
    <div class="card-subtitle">Pretty pretty!</div>
</ion-card>

Inside Ionic documentation, I didn't found anything related to load pages or images in background. 在Ionic文档中,我没有发现与后台加载页面或图像有关的任何内容。

I tried to use a this.nav.push(SecondPage); 我试图使用this.nav.push(SecondPage); in the home page and a ionViewDidLoad() {this.navCtrl.pop();} in the second before this.splashScreen.hide(); 在首页中,在第二个ionViewDidLoad() {this.navCtrl.pop();}之前,在this.splashScreen.hide(); , but it's a silly workaround, because it actually push and pop the pages while splashscreen is showing. ,但这是一个愚蠢的解决方法,因为它实际上在显示初始屏幕时推送并弹出页面。

There's a way to load all pages during the app start or even show a spinner before page loading? 有没有一种方法可以在应用启动期间加载所有页面,甚至在页面加载之前显示微调框?

tabs.html tabs.html

<ion-tabs id="navigationtabs" color="primary">
  <ion-tab [root]="tab1Root" tabTitle="Home" tabIcon="home"></ion-tab>
  <ion-tab [root]="tab2Root" tabTitle="About" tabIcon="ice-cream"></ion-tab>
  <ion-tab [root]="tab3Root" tabTitle="Contact" tabIcon="card"></ion-tab>
</ion-tabs>

tabs.ts tabs.ts

import { Component } from '@angular/core';
import { HomePage } from '../home/home';
import { AboutPage } from '../about/about';
import { ContactPage } from '../contact/contact';

@Component({
  templateUrl: 'tabs.html'
})
export class TabsPage {
  tab1Root: any = HomePage;
  tab2Root: any = AboutPage;
  tab3Root: any = ContactPage;
  constructor() {}
}

about.html (second page) about.html(第二页)

import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';

@Component({
  selector: 'page-about',
  templateUrl: 'about.html'
})
export class AboutPage {
  constructor(public navCtrl: NavController) {}
}

about.html (second page) about.html(第二页)

<ion-header>
  <ion-navbar color="primary">
   <ion-title><img src="assets/logo.png" style="display:inline-block" width="112px"/></ion-title>
    <ion-buttons end>
      <button ion-button icon-only>
      </button>
    </ion-buttons>
  </ion-navbar>
</ion-header>

<ion-content class="card-background-page">

  <ion-card>
    <img src="assets/sorvete.png"/>
    <div class="card-title">Sorvetes</div>
    <div class="card-subtitle">Deliciosas combinações para você escolher!</div>
  </ion-card>

  <ion-card>
    <img src="assets/cobertura.png"/>
    <div class="card-title">Coberturas</div>
    <div class="card-subtitle">Para você dar o toque final no seu sorvete!</div>
  </ion-card>

  <ion-card>
    <img src="assets/acai.png"/>
    <div class="card-title">Açaí na Tigela</div>
    <div class="card-subtitle">Prove o saboroso açaí na tigela!</div>
  </ion-card>

  <ion-card>
    <img src="assets/gelatos.png"/>
    <div class="card-title">Gelatos Italianos</div>
    <div class="card-subtitle">Para paladares exigentes!</div>
  </ion-card>

  <ion-card>
    <img src="assets/doce.png"/>
    <div class="card-title">Doces</div>
    <div class="card-subtitle">De dar água na boca!</div>
  </ion-card>

  <ion-card>
    <img src="assets/salgado.png"/>
    <div class="card-title">Salgados</div>
    <div class="card-subtitle">Saborosos lanches para você apreciar!</div>
  </ion-card>

  <ion-card>
    <img src="assets/outro.png"/>
    <div class="card-title">Bebidas</div>
  </ion-card>

</ion-content>

If you have code that needs to be run in the other pages before they show, you can import the other pages into your homepage and do everything you need to do there. 如果您的代码需要在其他页面上显示之前运行,则可以将其他页面导入到主页中,并在其中进行所有操作。 When you switch pages, all ionic has to do is load the dom 切换页面时,所有离子操作只需加载dom

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM