微信小程序清除計時器


需要在Pages的data里設置一個初始變量接收計時器參數,這里用setinterval
在請求成功時設置data里的setinterval為timer(計時器名稱)
在onhide和onunload里添加clearInterval(this.data.setinterval);
 
// hyb_yl/hezuoyiyuan/detail.js
var app = getApp();
const WxParse = require('../../wxParse/wxParse.js');
Page({

/**
* 頁面的初始數據
*/
data: {
setinterval: "",
},
/**
 
* 生命周期函數--監聽頁面隱藏
*/
onHide: function () {
let e = this;
clearInterval(e.data.setinterval);
},

/**
* 生命周期函數--監聽頁面卸載
*/
onUnload: function () {
let e = this;
clearInterval(e.data.setinterval);
},

/**
* 頁面相關事件處理函數--監聽用戶下拉動作
*/
onPullDownRefresh: function () {
 
},

/**
* 頁面上拉觸底事件的處理函數
*/
onReachBottom: function () {
 
},

/**
* 用戶點擊右上角分享
*/
onShareAppMessage: function () {
 
},
createVideo:function(e){
  onsole.log(e)
  var that = this;
  var mopenid=wx.getStorageSync('openid');
  var timer = setInterval(function(){
  app.util.request({
  url: "entry/wxapp/Myzhuan",
  data: {
    openid: mopenid
  },
  success: function (a) {
    console.log(222, a)
    if (a.data.data.uid == undefined | a.data.data.z_yy_sheng == '0') {
    wx.navigateTo({
    url: "/hyb_yl/liao_detail/liao_detail?name=" + n + "&fid=" + e + "&tid=" + s + "&state=new&time=" + that.data.time_en + "&openid=" + openid + "&t_uid=" + uid + "&mopenid=" + mopenid
    });
    } else {
    wx.showModal({
    title: '你已經是專家了'
      })
    }
    }
  })
},2000)
  that.setData({
    setinterval:timer
  })
},
look_more: function () {
var a = this.data.xssum + 4
this.setData({
xssum: a
})
console.log(this.data.xssum)
},
aaaabtn:function(t){
console.log(t)
},
commentsxq: function (e) {
console.log(e)
 
var str = this.data.zjcommentsAll[e.currentTarget.dataset.index].content;
var val = "";
for (var i = 0; i < str.length; i++) {
if (val == "") val = str.charCodeAt(i);
else val += "," + str.charCodeAt(i);
}
wx.navigateTo({ //保留當前頁面,跳轉到應用內的某個頁面(最多打開5個頁面,之后按鈕就沒有響應的)
url: "../commentsxq/commentsxq?content=" + val + '&score=' + this.data.zjcommentsAll[e.currentTarget.dataset.index].score + "&time=" + this.data.zjcommentsAll[e.currentTarget.dataset.index].time + '&username=' + this.data.xx[this.data.zjcommentsAll[e.currentTarget.dataset.index].id] + '&userImg=' + this.data.yyy[this.data.zjcommentsAll[e.currentTarget.dataset.index].id] + '&images=' + this.data.zjcommentsAll[e.currentTarget.dataset.index].images
})
}
})


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM