账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    ionic3如何使用返回按钮返回上一页?
    97
    0

    ionic做的页面在浏览器访问时点击返回按钮直接就退出这个页面了,如何修改成返回上一个页面

    2
    打赏
    收藏
    点击回答
        全部回答
    • 0
    • 残阳秋鹤影 普通会员 1楼

      在ionic3中,你可以在组件或服务中使用返回按钮返回上一页,以下是一个简单的示例:

      1. App组件中,设置返回按钮的样式和事件监听器:

      ```typescript import { Component } from '@angular/core'; import { IonBottomSheet, IonBottomSheetRef } from '@ionic/material/bottom-sheet'; import { Router } from '@angular/router';

      @Component({ selector: 'app-app', templateUrl: './app.component.html', styleUrls: ['./app.component.css'] }) export class AppComponent { bottomSheetRef: IonBottomSheetRef;

      constructor(private router: Router) {}

      goToPreviousPage() { this.bottomSheetRef?.close(); this.router.navigate(['/prev']); } } ```

      1. app.component.html文件中,添加返回按钮:

      html <ion-bottom-sheet #bottomSheetRef (ionBottomSheetClosing)="goToPreviousPage()"> <ion-button (click)="goToPreviousPage()">Previous</ion-button> </ion-bottom-sheet>

      1. app.component.ts文件中,处理返回按钮的点击事件:

      ```typescript import { Component, OnInit } from '@angular/core'; import { IonBottomSheet } from '@ionic/material/bottom-sheet'; import { Router } from '@angular/router';

      @Component({ selector: 'app-app', templateUrl: './app.component.html', styleUrls: ['./app.component.css'] }) export class AppComponent implements OnInit { bottomSheetRef: IonBottomSheetRef;

      constructor(private router: Router) {}

      ngOnInit() { this.bottomSheetRef = this.createBottomSheetRef(); }

      createBottomSheetRef() { return new IonBottomSheet({ heading: 'Previous Page', icon: 'ios-arrow-back', cancelText: 'Cancel', confirmText: 'Previous', headerText: 'Go to Previous Page', footerText: 'Done' }); }

      goToPreviousPage() { this.bottomSheetRef?.close(); this.router.navigate(['/prev']); } } ```

      在这个示例中,我们首先在app.component.ts中创建了一个IonBottomSheetRef对象,然后在ngOnInit方法中初始化它。然后,我们定义了一个名为createBottomSheetRef的方法,该方法返回一个新的IonBottomSheet对象,该对象包含了返回按钮的样式、图标和文本。

      app.component.html文件中,我们添加了一个返回按钮,并在ionBottomSheetClosing事件处理函数中调用了createBottomSheetRef方法创建一个新的IonBottomSheet对象,然后关闭它并调用goToPreviousPage方法,以返回上一页。

      注意:在实际使用中,你可能需要根据你的需求和项目的具体配置来调整这个示例,例如更改返回按钮的样式、图标、文本等,以及在createBottomSheetRef方法中添加更多的自定义属性和事件监听器。

    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部