多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
**wxml:** ``` <!--按钮--> <view style="{{isShowToast?'position:fixed;':''}}"> <view class="btn" bindtap="clickBtn">button</view> </view> <!--mask--> <view class="toast_mask" wx:if="{{isShowToast}}"></view> <!--以下为toast显示的内容--> <view class="toast_content_box" wx:if="{{isShowToast}}"> <view class="toast_content"> <view class="toast_content_text"> {{toastText}} </view> </view> </view> ``` **wxss:** ``` Page { background: #fff; } /*按钮*/ .btn { font-size: 28rpx; padding: 15rpx 30rpx; width: 100rpx; margin: 20rpx; text-align: center; border-radius: 10rpx; border: 1px solid #000; } /*mask*/ .toast_mask { opacity: 0; width: 100%; height: 100%; overflow: hidden; position: fixed; top: 0; left: 0; z-index: 888; } /*toast*/ .toast_content_box { display: flex; width: 100%; height: 100%; justify-content: center; align-items: center; position: fixed; z-index: 999; } .toast_content { width: 50%; padding: 20rpx; background: rgba(0, 0, 0, 0.5); border-radius: 20rpx; } .toast_content_text { height: 100%; width: 100%; color: #fff; font-size: 28rpx; text-align: center; } ``` **js:** ``` Page({ data: { //toast默认不显示 isShowToast: false }, showToast: function () { var _this = this; // toast时间 _this.data.count = parseInt(_this.data.count) ? parseInt(_this.data.count) : 3000; // 显示toast _this.setData({ isShowToast: true, }); // 定时器关闭 setTimeout(function () { _this.setData({ isShowToast: false }); }, _this.data.count); }, /* 点击按钮 */ clickBtn: function () { console.log("你点击了按钮") //设置toast时间,toast内容 this.setData({ count: 1500, toastText: 'Michael’s Toast' }); this.showToast(); } }) ``` //修改原生的提示图标 ``` wx.showToast({ image: '/images/musician-detail_toast_failure.png', title: '取消成功', icon: 'none', duration: 2000 }) ```