这篇文章主要给大家介绍了微信小程序开发之toast提示插件的相关资料,文中通过示例代码介绍的非常详细,对大家具有一定的参考学习价值,需要的朋友们下面来一起看看吧。
前言
3月28号微信更新了版本,showToast可以通过image参数修改默认icon了,最大时间也取消了。
以上两个更新实用很多,但icon还是无法去除。显示形式有点单一,无法自定义,可能后续更新会增加更多功能。下面来看看本文的详细内容:


下载文章下面的文件,放在根目录。

然后在app.js中引入js并添加到App中,如下:
1 2 3 4 5 | var wxToast = require(& #39;toast/toast.js')
App({
wxToast ,
onLaunch: function () {}
})
|
在app.wxss中添加如下css:
1 | .wxToast_mask{ width : 100% ; height : 100% ; position : fixed ; left : 0px ; top : 0px ; z-index : 10000 ; background :rgba( 0 , 0 , 0 , 0 );opacity: 0 ; display : none }.wxToast_show{ display : block }.wxToast_content{ max-width : 80% ; min-width : 90px ; position : absolute ; left : 50% ; top : 20% ;transform:translate 3 d( -50% , 0 , 0 ); padding : 15px ; color : #fff ; font-size : 17px ; text-align : center ;border-radius: 5px ; background :rgba( 0 , 0 , 0 ,. 8 )}.wxToast_img{ width : 55px ; height : 55px ; display : block ; margin : 0 auto 8px auto }
|
接着在页面xxx.wxml中添加如下内容:
1 2 | <import src= "../../toast/toast.wxml" />
<template is= "wxToast" data= "{{...wxToastConfig}}" ></template>
|
最后在页面xxx.js中就可以调用了。
1 2 3 4 5 6 7 8 9 10 | var app = getApp();
Page({
toast: {
app.wxToast({
title : & #39;加载中'
})
},
onLoad : function ( ){}
})
|
更多方法:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | app.wxToast({
title : & #39;验证码错误', //标题,不写默认正在加载
img : & #39;../../images/cc.png', //icon路径,不写不显示
imgClass : & #39;images', //icon添加class类名
contentClass : & #39;content', //内容添加class类名
duration : 3000,
tapClose : false ,
show : function (){
console.log(& #39;显示啦')
},
hide : function (){
console.log(& #39;消失啦')
}
});
|
1 2 3 4 | app.wxToast( false );
setTimeout( function (){
app.wxToast( false );
},3000)
|
点击这里下载文件。
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。