微信小程序如何實(shí)現(xiàn)自定義Toast

這篇文章主要介紹微信小程序如何實(shí)現(xiàn)自定義Toast,文中介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們一定要看完!

創(chuàng)新互聯(lián)公司專(zhuān)注于梁河網(wǎng)站建設(shè)服務(wù)及定制,我們擁有豐富的企業(yè)做網(wǎng)站經(jīng)驗(yàn)。 熱誠(chéng)為您提供梁河營(yíng)銷(xiāo)型網(wǎng)站建設(shè),梁河網(wǎng)站制作、梁河網(wǎng)頁(yè)設(shè)計(jì)、梁河網(wǎng)站官網(wǎng)定制、微信小程序服務(wù),打造梁河網(wǎng)絡(luò)公司原創(chuàng)品牌,更為您提供梁河網(wǎng)站排名全網(wǎng)營(yíng)銷(xiāo)落地服務(wù)。

微信小程序 自定義Toast實(shí)例代碼

Toast樣式可以根據(jù)需求自定義,本例中是圓形

微信小程序如何實(shí)現(xiàn)自定義Toast

<!--按鈕-->  
<view class="btn" bindtap="btn_toast">自定義Toast</view>  
<!--以下為toast顯示的內(nèi)容 opacity為透明度-->  
<view class="toast_box"  wx:if="{{isShowToast}}">   
  {{toastText}}   
</view>  
<view class="toast_box"  wx:if="{{isShowToast}}">   
  {{toastText1}}   
</view>
Page {  
 background: #f9f9f9;  
}  
/*按鈕*/  
.btn {  
 width: 20%;   
 margin-left: 38%; 
 margin-top: 100rpx; 
 text-align: center;  
 border-radius: 10rpx;  
 border: 10px solid #f00;  
 background: #f00; 
 color: #fff;  
 font-size: 22rpx; 
}  
/*toast*/  
.toast_box {  
 width: 30%;  
 height: 221rpx; 
 margin-top: 60rpx;  
 margin-left: 35%; 
 text-align: center;  
 border-radius: 166rpx;  
 background: #f00; 
 color: #fff;  
 font-size: 32rpx; 
 line-height: 220rpx;  
}
Page({ 
 
 /** 
  * 頁(yè)面的初始數(shù)據(jù) 
  */ 
 data: { 
  //toast默認(rèn)不顯示  
  isShowToast: false   
 }, 
 showToast: function () { 
  var _this = this; 
  // toast時(shí)間  
  _this.data.count = parseInt(_this.data.count) ? parseInt(_this.data.count) : 1000; 
  // 顯示toast  
  _this.setData({ 
   isShowToast: true, 
  }); 
  // 定時(shí)器關(guān)閉  
  setTimeout(function () { 
   _this.setData({ 
    isShowToast: false 
   }); 
  }, _this.data.count); 
 }, 
 /* 點(diǎn)擊按鈕 */ 
 btn_toast: function () { 
  console.log("點(diǎn)擊了按鈕") 
  //設(shè)置toast時(shí)間,toast內(nèi)容  
  this.setData({ 
   count: 1500, 
   toastText: '自定義', 
   toastText1: 'Toast' 
  }); 
  this.showToast(); 
 },  
 /** 
  * 生命周期函數(shù)--監(jiān)聽(tīng)頁(yè)面加載 
  */ 
 onLoad: function (options) { 
  
 },})

以上是“微信小程序如何實(shí)現(xiàn)自定義Toast”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對(duì)大家有幫助,更多相關(guān)知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!

當(dāng)前文章:微信小程序如何實(shí)現(xiàn)自定義Toast
轉(zhuǎn)載源于:http://muchs.cn/article22/jehcjc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供虛擬主機(jī)、域名注冊(cè)、App設(shè)計(jì)、外貿(mào)網(wǎng)站建設(shè)、全網(wǎng)營(yíng)銷(xiāo)推廣企業(yè)網(wǎng)站制作

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

成都網(wǎng)站建設(shè)公司