1、ActionSheet 官方文档:https://ionicframework.com/docs/api/action-sheet

<ion-header>
<ion-toolbar>
<ion-buttons slot="start">
<ion-back-button defaultHref="/tabs/tab1"></ion-back-button>
</ion-buttons>
<ion-title>actionsheet</ion-title>
</ion-toolbar>
</ion-header> <ion-content padding> <ion-button (click)="showAction()">
弹出actionSheet
</ion-button>
</ion-content>
import { Component, OnInit } from '@angular/core';

import { ActionSheetController } from '@ionic/angular';

@Component({
selector: 'app-actionsheet',
templateUrl: './actionsheet.page.html',
styleUrls: ['./actionsheet.page.scss'],
})
export class ActionsheetPage implements OnInit { constructor(public actionSheetController: ActionSheetController) {} ngOnInit() {
} async showAction(){ const actionSheet = await this.actionSheetController.create({
header: '我是actionsheet的标题',
mode:'ios', /*修改action的平台*/
buttons: [{
text: '删除',
role: 'destructive',
icon: 'trash',
handler: () => {
console.log('Delete clicked');
}
}, {
text: '分享',
icon: 'share',
handler: () => {
console.log('Share clicked');
}
}, {
text: '收藏',
icon: 'heart',
handler: () => {
console.log('Favorite clicked');
}
}, {
text: '取消',
role: 'cancel',
handler: () => {
console.log('Cancel clicked');
}
}]
});
await actionSheet.present(); } }

2、Alert 官方文档:https://ionicframework.com/docs/api/alert

<ion-header>
<ion-toolbar>
<ion-buttons slot="start">
<ion-back-button defaultHref="/tabs/tab1"></ion-back-button>
</ion-buttons>
<ion-title>alert</ion-title>
</ion-toolbar>
</ion-header>
<ion-content padding>
<ion-button (click)="presentAlert()">
presentAlert
</ion-button>
<ion-button (click)="presentAlertMultipleButtons()">
确定要删除吗
</ion-button>
<ion-button (click)="presentAlertPrompt()">
alert放表单
</ion-button>
</ion-content>
import { Component, OnInit } from '@angular/core';

import { AlertController } from '@ionic/angular';

@Component({
selector: 'app-alert',
templateUrl: './alert.page.html',
styleUrls: ['./alert.page.scss'],
})
export class AlertPage implements OnInit { constructor(public alertController: AlertController) {} ngOnInit() {
} async presentAlert() {
const alert = await this.alertController.create({
header: '提示信息',
message: '你已经支付成功了...',
buttons: ['确认']
}); await alert.present();
} async presentAlertMultipleButtons() {
const alert = await this.alertController.create({
header: '提示信息!',
message: '您确定要删除吗?',
buttons: [
{
text: '取消',
role: 'cancel',
cssClass: 'secondary', //注意自定义class写在全局
handler: (blah) => {
console.log('Confirm Cancel: blah');
}
}, {
text: '确定',
handler: () => {
console.log('Confirm Okay');
}
}
]
}); await alert.present();
} async presentAlertPrompt() {
const alert = await this.alertController.create({
header: 'Prompt!',
inputs: [
{
name: 'name1',
type: 'text',
placeholder: 'Placeholder 1'
},
{
name: 'name2',
type: 'text',
id: 'name2-id',
value: 'hello',
placeholder: 'Placeholder 2'
},
{
name: 'name3',
value: 'http://ionicframework.com',
type: 'url',
placeholder: 'Favorite site ever'
},
// input date with min & max
{
name: 'name4',
type: 'date',
min: '2017-03-01',
max: '2018-01-12'
},
// input date without min nor max
{
name: 'name5',
type: 'date'
},
{
name: 'name6',
type: 'number',
min: -5,
max: 10
},
{
name: 'name7',
type: 'number'
}
],
buttons: [
{
text: 'Cancel',
role: 'cancel',
cssClass: 'secondary',
handler: () => {
console.log('Confirm Cancel');
}
}, {
text: 'Ok',
handler: (result) => { //获取表单输入的值
console.log(result);
}
}
]
}); await alert.present();
} }

3、Toast 官方文档:https://ionicframework.com/docs/api/toast

<ion-header>
<ion-toolbar>
<ion-buttons slot="start">
<ion-back-button defaultHref="/tabs/tab1"></ion-back-button>
</ion-buttons>
<ion-title>toast</ion-title>
</ion-toolbar>
</ion-header> <ion-content padding> <ion-button (click)="presentToast()">
presentToast
</ion-button> <ion-button (click)="presentToastWithOptions()">
presentToastWithOptions
</ion-button> </ion-content>
import { Component, OnInit } from '@angular/core';

import { ToastController } from '@ionic/angular';
@Component({
selector: 'app-toast',
templateUrl: './toast.page.html',
styleUrls: ['./toast.page.scss'],
})
export class ToastPage implements OnInit {
constructor(public toastController: ToastController) {}
ngOnInit() {
} async presentToast() {
const toast = await this.toastController.create({
message: '登录成功',
duration: 2000,
position: 'middle',
color:'dark',
cssClass:'mytoast' /*cssClass必须写在全局*/
});
toast.present();
} async presentToastWithOptions() {
const toast = await this.toastController.create({
message: 'Click to Close',
showCloseButton: true,
position: 'top',
closeButtonText: 'Done'
});
toast.present();
} }

4、Loading 官方文档:https://ionicframework.com/docs/api/loading

<ion-header>
<ion-toolbar>
<ion-buttons slot="start">
<ion-back-button defaultHref="/tabs/tab1"></ion-back-button>
</ion-buttons>
<ion-title>loading</ion-title>
</ion-toolbar>
</ion-header> <ion-content padding> <ion-button (click)="presentLoading()">
presentLoading
</ion-button> <ion-button (click)="presentLoadingWithOptions()">
presentLoadingWithOptions
</ion-button>
</ion-content>
import { Component, OnInit } from '@angular/core';

import { LoadingController } from '@ionic/angular';

@Component({
selector: 'app-loading',
templateUrl: './loading.page.html',
styleUrls: ['./loading.page.scss'],
})
export class LoadingPage implements OnInit {
constructor(public loadingController: LoadingController) {} ngOnInit() {
} async presentLoading() {
const loading = await this.loadingController.create({
message: '加载中...',
duration: 5000
});
await loading.present(); //事件
await loading.onDidDismiss();
// console.log({ role, data });
console.log('Loading dismissed!');
} async presentLoadingWithOptions() {
const loading = await this.loadingController.create({
// spinner: null,
duration: 5000, //延迟时间
message: '请等待...',
translucent: true, //半透明的
cssClass: 'custom-class custom-loading' //注意自定义样式要写在全局
});
return await loading.present();
} }

5、Ionic4 手势相关事件

详情参考:http://www.ionic.wang/article-index-id-155.html 1、首先需要安装 hammerjs

ionic4 中的 gestures 手势事件包括: tap, press, pan, swipe, rotate, and pinch events 等。详细使用方法参考:

详情参考:http://www.ionic.wang/article-index-id-155.html

1、首先需要安装 hammerjs

npm install hammerjs --save

2、在项目的 src/main.ts 中引入 hammerjs

import 'hammerjs';

3、在项目中使用

<ion-button (press)="doPress()">
长按触发的事件
</ion-button>
<ion-button (tap)="doTap()">
点击触发的事件
</ion-button>

说明:如果未来的 ionic4.x 版本可以直接使用手势事件的话忽略上面的安装引入过程。

<ion-header>
<ion-toolbar>
<ion-title>gestures</ion-title>
</ion-toolbar>
</ion-header> <ion-content padding> <ion-button (tap)="doTap()">
点击事件
</ion-button> <ion-button (press)="doPress()">
长按事件
</ion-button> <ion-list>
<ion-item>
<ion-label (press)="doPress()">衣服</ion-label>
</ion-item>
<ion-item>
<ion-label (press)="doPress()">鞋子</ion-label>
</ion-item> <ion-item>
<ion-label (press)="doPress()">女装</ion-label>
</ion-item>
</ion-list>
</ion-content>
import { Component, OnInit } from '@angular/core';

import { AlertController } from '@ionic/angular';
@Component({
selector: 'app-gestures',
templateUrl: './gestures.page.html',
styleUrls: ['./gestures.page.scss'],
})
export class GesturesPage implements OnInit { constructor(public alertController: AlertController) {} ngOnInit() {
}
doTap(){ console.log('tap tap ...')
} async doPress(){
const alert = await this.alertController.create({ backdropDismiss:false,
header: '提示',
message: '确定要删除吗!',
buttons: [
{
text: '取消',
role: 'cancel',
cssClass: 'secondary',
handler: (blah) => {
console.log('Confirm Cancel: blah');
}
}, {
text: '确定',
handler: () => {
console.log('Confirm Okay');
}
}
]
});
await alert.present(); }
}

Ionic4.x Javascript 扩展 ActionSheet Alert Toast Loading 以及 ionic 手势相 关事件的更多相关文章

  1. iOS Webview 实现修改javascript confirm 和 alert

    贴代码: @interface UIWebView (JavaScriptAlert) -(void) webView:(UIWebView *)sender runJavaScriptAlertPa ...

  2. Bootstrap Modal 框 alert confirm loading

    /** * Created by Administrator on 2016/5/4. */ /** * 模态窗口 */ window.Modal = { tpls:{ alert:'<div ...

  3. 扩展javascript扩展(类,对象,原型)

     扩展javascript扩展(类,对象,原型)

  4. Web前端——JavaScript扩展补充

    JS补充 document也是windows的一个子对象 a标签点击事件 要想设置点击a标签,执行某种方法,推荐在a标签的herf属性使用JavaScript伪协议,实现点击之后执行的js方法,而不是 ...

  5. JavaScript扩展原型链浅析

    前言 上文对原型和原型链做了一些简单的概念介绍和解析,本文将浅析一些原型链的扩展. javaScript原型和原型链 http://lewyon.xyz/prototype.html 扩展原型链 使用 ...

  6. vue中alert toast confirm loading 公用

    import Vue from 'vue' import { ToastPlugin, AlertPlugin, ConfirmPlugin, LoadingPlugin } from 'vux' / ...

  7. Javascript扩展String.prototype实现格式金额、格式时间、字符串连接、计算长度、是否包含、日期计算等功能

    <script src="Js/jquery-3.1.1.min.js"></script> <script type="text/java ...

  8. JavaScript 扩展运算符

    扩展运算符格式扩展运算符格式很简单,就是三个点(...) 扩展运算符作用???扩展运算符允许一个表达式在期望多个参数(用于函数调用)或多个元素(用于数组字面量)或多个变量(用于解构赋值)的位置扩展. ...

  9. JavaScript实现自定义alert弹框

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAh0AAAFkCAYAAACEpYlzAAAfj0lEQVR4nO3dC5BddZ0n8F93pxOQCO

随机推荐

  1. jstack、jmc、jhat工具使用详解

    jstack: 在上一次[https://www.cnblogs.com/webor2006/p/10669472.html]jcmd中也可以获取线程的堆栈信息,回顾一下: 其实在JDK中还有另一个专 ...

  2. HDU-1237- 简单计算器--栈的基本应用

    简单计算器 Problem Description 读入一个只包含 +, -, *, / 的非负整数计算表达式,计算该表达式的值.   Input 测试输入包含若干测试用例,每个测试用例占一行,每行不 ...

  3. ui自动化测试 SeleniumBase

    ui自动化 SeleniumBase SeleniumBase是一个自动化web测试框架,它的设计pyse相似,基于selenium和unittest封装的框架,api多,支持命令行多参数执行 文档地 ...

  4. PL/SQL存储过程

    一.概述 过程和函数统称为PL/SQL子程序,他们是被命名的PL/SQL块,均存储于数据库中. 并通过输入.输出和输入输出参数与其调用者交换信息.唯一区别是函数总向调用者返回数据. 二.存储过程详解 ...

  5. CSP-S 2019 第二轮 退役记

    Day 0 复习数论,复习网络流,复习动态DP,复习ac自动机,复习后缀自动机- Day 1 进考场,得到解压密码,跟时事热点没有什么关系. 感觉键盘有点难受,右半部分包括退格.方向键.回车都比较黏. ...

  6. 51、[源码]-Spring容器创建-容器创建完成

    51.[源码]-Spring容器创建-容器创建完成 12.finishRefresh();完成BeanFactory的初始化创建工作:IOC容器就创建完成: 1).initLifecycleProce ...

  7. LeetCode 320. Generalized Abbreviation

    原题链接在这里:https://leetcode.com/problems/generalized-abbreviation/ 题目: Write a function to generate the ...

  8. 1-git的安装和基本使用

    说一下,我希望都要会用git,git很好用, 代码管理,多人合作开发一个项目,版本记录等等 https://gitee.com/    去上面注册一个账户 https://git-scm.com/do ...

  9. 后缀数组 1031: [JSOI2007]字符加密Cipher

    /*1031: [JSOI2007]字符加密Cipher Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 4926 Solved: 2020[Submit ...

  10. 洛谷P1016 旅行家的预算 题解

    主要就是注意一下各个变量的类型别弄混了 https://www.luogu.org/problem/P1016 #include<cstdio> using namespace std; ...