需要在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
})
}
})