Home > Web Front-end > JS Tutorial > How to use toast message dialog box in WeChat applet

How to use toast message dialog box in WeChat applet

亚连
Release: 2018-06-21 17:47:40
Original
2014 people have browsed it

This article mainly introduces the function of using the toast message dialog box in the WeChat applet to prompt the user to forget to enter the user name or password. It analyzes in detail the relevant operating skills of the toast component to implement the message prompt function in the form of examples, and comes with source code for readers to download. For reference, friends in need can refer to

This article describes the example of the WeChat applet using the toast message dialog box to prompt the user to forget to enter the user name or password. Share it with everyone for your reference, as follows:

Key code

① index.wxml

<form bindsubmit="formBindsubmit" bindreset="formReset">
 <view style="display:flex;">
  <label>用户名:</label>
  <input name="userName" placeholder="请输入用户名!" />
 </view>
 <view style="display:flex;">
  <label>密码:</label>
  <input name="psw" placeholder="请输入密码!" password="true" />
 </view>
 <view style="display:flex;margin-top:30px;">
  <button style="width:30%;" formType="submit" >登录</button>
  <button style="width:30%" formType="reset" >重置</button>
 </view>
</form>
<view>{{userName}}</view>
<view>{{psw}}</view>
<toast duration="2000" hidden="{{toastHidden}}" bindchange="toastBindChange">用户名或密码不能为空!</toast>
Copy after login

② index.js

Page({
 data:{
  // text:"这是一个页面"
  toastHidden:true,
  userName:&#39;&#39;,
  psw:&#39;&#39;
 },
 formBindsubmit:function(e){
  if(e.detail.value.userName.length==0||e.detail.value.psw.length==0){
   this.setData({
    toastHidden:!this.data.toastHidden
   })
  }else{
   this.setData({
    tip:&#39;&#39;,
    userName:&#39;用户名:&#39;+e.detail.value.userName,
    psw:&#39;密码:&#39;+e.detail.value.psw
   })
  }
 },
 formReset:function(){
  this.setData({
   userName:&#39;&#39;,
   psw:&#39;&#39;
  })
 },
 toastBindChange:function(){
  this.setData({
    toastHidden:!this.data.toastHidden
  })
 }
})
Copy after login

The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.

Related articles:

How to build a universal data simulation framework for the front end (detailed tutorial)

How to implement flux on knockoutjs

How to implement seamless scrolling components using vue

About the difficulty of JavaScript array operations (detailed tutorial)

How to implement the like function in WeChat mini program

The above is the detailed content of How to use toast message dialog box in WeChat applet. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template