当前位置:网站首页>微信小程序中使用wx.showToast()进行界面交互
微信小程序中使用wx.showToast()进行界面交互
2022-07-07 04:02:00 【richest_qi】
前情提要
微信小程序中使用 wx.showToast() 显示消息提示框,这个API接收一个对象作为参数,该对象包含以下属性:
title,提示的内容,必填项。icon,显示的图标,非必填项,有以下四个可选值,其中默认值是success。success,成功图标,此时title文本最多显示7个汉字。error,失败图标,此时title文本最多显示7个汉字长度。loading,加载图标,此时title文本最多显示7个汉字长度。none,不显示图标,此时title文本最多可显示两行。
image,自定义图标的本地路径,image的优先级高于icon。duration,提示的延迟时间。mask,是否显示透明蒙层(透明蒙层可防止触摸穿透),布尔值,默认是false,即不显示透明蒙层。success,接口调用成功的回调。fail,接口调用失败的回调。complete,接口调用结束(不论成功或失败)的回调。
小程序项目
代码涉及的文件有:
- app.json
- pages/index/index.wxml
- pages/index/index.wxss
- pages/index/index.js

app.json
{
"pages": [
"pages/index/index"
],
"window": {
"navigationBarBackgroundColor": "#0149af",
"navigationBarTitleText": "登录中心",
"navigationBarTextStyle": "white"
},
"style": "v2",
"sitemapLocation": "sitemap.json"
}
pages/index/index.wxml
<view class="container">
<view class="title">登录</view>
<view class="list">
<view class="item">
<input type="text" data-type="username" bindinput="handleInput" placeholder="用户名" />
</view>
<view class="item">
<input type="text" password data-type="password" bindinput="handleInput" placeholder="密码" />
</view>
</view>
<button size="mini" bindtap="login">登录</button>
</view>
pages/index/index.wxss
.container{
padding: 20rpx;
}
.container .title{
padding: 20rpx 0;
border-bottom: 1px solid #ddd;
font-weight: bold;
font-size: 32rpx;
}
.list{
margin: 40rpx auto 20rpx;
}
.item{
margin: 12rpx 0;
padding: 0 20rpx;
border: 1px solid #ddd;
border-radius: 6rpx;
}
.item input{
width: 100%;
height: 60rpx;
font-size: 28rpx;
}
button{
font-weight: normal;
font-size: 28rpx!important;
color: #fff;
background: #0149af;
}
pages/index/index.js
Page({
data:{
username:"",
password:""
},
handleInput(e){
const type = e.target.dataset.type;
this.setData({
[type]:e.detail.value
})
},
login(){
const {
username,password} = this.data;
if(!username){
wx.showToast({
title: '请输入您的用户名',
icon:'error'
})
return;
}
if(!password){
wx.showToast({
title: '请输入您的密码',
icon:'error'
})
return;
}
wx.showToast({
title: '登录成功'
})
}
})
相关链接
边栏推荐
- Leetcode-543. Diameter of Binary Tree
- Unity C function notes
- ../ And/
- About some details of final, I have something to say - learn about final CSDN creation clock out from the memory model
- 二、并发、测试笔记 青训营笔记
- Nesting and splitting of components
- [2022 CISCN]初赛 web题目复现
- Blue Bridge Cup Birthday candles (violence)
- Fast quantitative, abbkine protein quantitative kit BCA method is coming!
- 聊聊异步编程的 7 种实现方式
猜你喜欢

1140_ SiCp learning notes_ Use Newton's method to solve the square root

弹性布局(二)

About some details of final, I have something to say - learn about final CSDN creation clock out from the memory model

$parent (get parent component) and $root (get root component)

Wechat applet full stack development practice Chapter 3 Introduction and use of APIs commonly used in wechat applet development -- 3.10 tabbar component (I) how to open and use the default tabbar comp

Flexible layout (I)

考研失败,卷不进大厂,感觉没戏了

1141_ SiCp learning notes_ Functions abstracted as black boxes

Non empty verification of collection in SQL

抽丝剥茧C语言(高阶)指针的进阶
随机推荐
Torefs API and toref API
"Xiaodeng in operation and maintenance" meets the compliance requirements of gdpr
【Liunx】进程控制和父子进程
关于二进制无法精确表示小数
I failed in the postgraduate entrance examination and couldn't get into the big factory. I feel like it's over
面试官:你都了解哪些开发模型?
Readonly read only
按键精灵采集学习-矿药采集及跑图
Leetcode-543. Diameter of Binary Tree
Wechat applet full stack development practice Chapter 3 Introduction and use of APIs commonly used in wechat applet development -- 3.9 introduction to network interface (IX) extending the request3 met
ROS2规划系统plansys2简单的例子
Jenkins远程构建项目超时的问题
Leetcode-206. Reverse Linked List
计算机服务中缺失MySQL服务
After 95, Alibaba P7 published the payroll: it's really fragrant to make up this
1089: highest order of factorial
[semantic segmentation] - multi-scale attention
Leetcode-226. Invert Binary Tree
毕设-基于SSM大学生兼职平台系统
深度学习花书+机器学习西瓜书电子版我找到了