小程序
小游戏
企业微信
微信支付
扫描小程序码分享
wx:if条件渲染,第一次加载该页面,能出现弹窗,再从其他页面进去时,在轮询setInterval中,条件满足后,确实把数据变成true了,但是它的弹窗偶尔出现,如果是添加点击事件的话弹窗一定出现
6 个回答
加粗
标红
插入代码
插入链接
插入图片
上传视频
请自查,或者提供最简复现demo。你这大堆业务代码没时间给你看
你好,麻烦通过点击下方“反馈信息”按钮,提供出现问题的。
你离开了这个页面了,然后setinterval 还在跑,然后期望把弹窗弹出来?
你好,请具体描述问题出现的流程,并提供能复现问题的简单代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)。
不是,我又进入这个页面了,我的意思是我离开后又进来了,条件满足没弹窗,我console输出的true,在前台显示下是false
麻烦帮我看看,console输出true,但是前台还是false,快改一天了都
复现很难啊,涉及到数据库什么的,就是我用wx:if做了个弹窗,在一个轮询中查数据库的状态,第一次加载时数据库条件满足时,wx:if变为true,弹窗出现,离开当前页面再进来,轮询还在接着之前的继续,条件再次满足时,设为true但是弹窗不出现,我在前台显示下,显示的是false,给你截下那个轮训的代码
getOrderLength: function () {
var that = this;
var interval2 = that.data.interval2
interval2 = setInterval(function () {
that.setData({
interval2: interval2
})
wx.request({
url: api + '/selectNearbyOrder',
method: 'POST',
data: {
driverid: app.globalData.userid
},
header: {
"Content-Type": "application/x-www-form-urlencoded"
success: function (res) {
ordersAllTypeList: res.data.ordersAllTypeList,
// driverOrderListOk: res.data.driverOrderListOk
var isNew = false
var obj =app.globalData.obj
var valetObj = app.globalData.objValet
var errObj = app.globalData.objErr
var orderList = res.data.ordersAllTypeList
var index =-1
for(let i=0;i<orderList.length;i++){
var key = orderList[i].orderId
if(orderList[i].type===0){
if(obj.length>0){
for (let j = 0; j < obj.length; j++) {
if(key>obj[obj.length-1]){
isNew=true
obj.push(key)
break
}
}else{
}else if(orderList[i].type===1){
if (valetObj.length > 0) {
for (let j = 0; j < valetObj.length; j++) {
if (key > valetObj[valetObj.length - 1]) {
isNew = true
valetObj.push(key)
} else {
} else if (orderList[i].type===2){
if (errObj.length > 0) {
for (let j = 0; j < errObj.length; j++) {
if (key > errObj[errObj.length - 1]) {
errObj.push(key)
if(isNew){
index = i
indexChoose=i
src: app.globalData.musicSrc,
showModalView:true
console.log("state="+that.data.showModalState)
const innerAudioContext = wx.createInnerAudioContext()
innerAudioContext.autoplay = true
innerAudioContext.src = app.globalData.musicSrc
innerAudioContext.onPlay(() => {
innerAudioContext.onError((res) => {
console.log(res)
// this.audioCtx = wx.createAudioContext('myAudio')
// this.audioCtx.play()
wx.vibrateLong({
var from_address = res.data.ordersAllTypeList[i].from_address
var to_address = res.data.ordersAllTypeList[i].to_address
var longitude = res.data.ordersAllTypeList[i].longitude
var dimension = res.data.ordersAllTypeList[i].dimension
var to_longitude = res.data.ordersAllTypeList[i].to_longitude
var to_dimension = res.data.ordersAllTypeList[i].to_dimension
var type2 = res.data.ordersAllTypeList[i].type
var orderType = res.data.ordersAllTypeList[i].order_type
var orderId = res.data.ordersAllTypeList[i].orderId
var amount = res.data.ordersAllTypeList[i].amount
var carSharingValuation = app.globalData.errandValuation
var taxiValuation = app.globalData.errandValuation
var valetDriverValuation = app.globalData.errandValuation
var errandValuation = app.globalData.errandValuation
type2: type2,
orderType: orderType,
from: from_address,
to: to_address,
price: amount ,
showModalView: true
console.log(that.data.showModalView)
var latitudeNow3 = ''
var key = config.Config.key;
var myAmapFun = new amapFile.AMapWX({ key: key });
myAmapFun.getRegeo({
success: function (data) {
latitudeNow3 = data[0].latitude
var longitudeNow = data[0].longitude
var latitudeNow4 = longitudeNow + ',' + latitudeNow3;
var latitudeNow2 = to_longitude + ',' + to_dimension
// var key = config.Config.key;
// var myAmapFun = new amapFile.AMapWX({ key: key });
myAmapFun.getDrivingRoute({
origin: latitudeNow4,
destination: latitudeNow2,
var mile = data.paths[0].distance / 1000
mile: mile.toFixed(2),
// orderLength = res.data.ordersAllTypeList.length
if (app.globalData.driverState === 0) {
clearInterval(that.data.interval)
clearInterval(that.data.interval2)
}, 5000)
关注后,可在微信内接收相应的重要提醒。
请使用微信扫描二维码关注 “微信开放社区” 公众号
请自查,或者提供最简复现demo。你这大堆业务代码没时间给你看
你离开了这个页面了,然后setinterval 还在跑,然后期望把弹窗弹出来?
你好,请具体描述问题出现的流程,并提供能复现问题的简单代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)。
不是,我又进入这个页面了,我的意思是我离开后又进来了,条件满足没弹窗,我console输出的true,在前台显示下是false
麻烦帮我看看,console输出true,但是前台还是false,快改一天了都
复现很难啊,涉及到数据库什么的,就是我用wx:if做了个弹窗,在一个轮询中查数据库的状态,第一次加载时数据库条件满足时,wx:if变为true,弹窗出现,离开当前页面再进来,轮询还在接着之前的继续,条件再次满足时,设为true但是弹窗不出现,我在前台显示下,显示的是false,给你截下那个轮训的代码
getOrderLength: function () {
var that = this;
var interval2 = that.data.interval2
interval2 = setInterval(function () {
that.setData({
interval2: interval2
})
wx.request({
url: api + '/selectNearbyOrder',
method: 'POST',
data: {
driverid: app.globalData.userid
},
header: {
"Content-Type": "application/x-www-form-urlencoded"
},
success: function (res) {
that.setData({
ordersAllTypeList: res.data.ordersAllTypeList,
// driverOrderListOk: res.data.driverOrderListOk
})
var isNew = false
var obj =app.globalData.obj
var valetObj = app.globalData.objValet
var errObj = app.globalData.objErr
var orderList = res.data.ordersAllTypeList
var index =-1
for(let i=0;i<orderList.length;i++){
var key = orderList[i].orderId
if(orderList[i].type===0){
if(obj.length>0){
for (let j = 0; j < obj.length; j++) {
if(key>obj[obj.length-1]){
isNew=true
obj.push(key)
break
}
}
}else{
isNew=true
obj.push(key)
}
}else if(orderList[i].type===1){
if (valetObj.length > 0) {
for (let j = 0; j < valetObj.length; j++) {
if (key > valetObj[valetObj.length - 1]) {
isNew = true
valetObj.push(key)
break
}
}
} else {
isNew = true
valetObj.push(key)
}
} else if (orderList[i].type===2){
if (errObj.length > 0) {
for (let j = 0; j < errObj.length; j++) {
if (key > errObj[errObj.length - 1]) {
isNew = true
errObj.push(key)
break
}
}
} else {
isNew = true
errObj.push(key)
}
}
if(isNew){
index = i
indexChoose=i
that.setData({
src: app.globalData.musicSrc,
showModalView:true
})
console.log("state="+that.data.showModalState)
const innerAudioContext = wx.createInnerAudioContext()
innerAudioContext.autoplay = true
innerAudioContext.src = app.globalData.musicSrc
innerAudioContext.onPlay(() => {
})
innerAudioContext.onError((res) => {
console.log(res)
})
// this.audioCtx = wx.createAudioContext('myAudio')
// this.audioCtx.play()
wx.vibrateLong({
success: function (res) {
}
})
var from_address = res.data.ordersAllTypeList[i].from_address
var to_address = res.data.ordersAllTypeList[i].to_address
var longitude = res.data.ordersAllTypeList[i].longitude
var dimension = res.data.ordersAllTypeList[i].dimension
var to_longitude = res.data.ordersAllTypeList[i].to_longitude
var to_dimension = res.data.ordersAllTypeList[i].to_dimension
var type2 = res.data.ordersAllTypeList[i].type
var orderType = res.data.ordersAllTypeList[i].order_type
var orderId = res.data.ordersAllTypeList[i].orderId
var amount = res.data.ordersAllTypeList[i].amount
var carSharingValuation = app.globalData.errandValuation
var taxiValuation = app.globalData.errandValuation
var valetDriverValuation = app.globalData.errandValuation
var errandValuation = app.globalData.errandValuation
that.setData({
type2: type2,
orderType: orderType,
from: from_address,
to: to_address,
price: amount ,
showModalView: true
})
console.log(that.data.showModalView)
var latitudeNow3 = ''
var key = config.Config.key;
var myAmapFun = new amapFile.AMapWX({ key: key });
myAmapFun.getRegeo({
success: function (data) {
latitudeNow3 = data[0].latitude
var longitudeNow = data[0].longitude
var latitudeNow4 = longitudeNow + ',' + latitudeNow3;
var latitudeNow2 = to_longitude + ',' + to_dimension
// var key = config.Config.key;
// var myAmapFun = new amapFile.AMapWX({ key: key });
myAmapFun.getDrivingRoute({
origin: latitudeNow4,
destination: latitudeNow2,
success: function (data) {
var mile = data.paths[0].distance / 1000
that.setData({
mile: mile.toFixed(2),
})
}
})
// orderLength = res.data.ordersAllTypeList.length
}
})
break
}
}
}
})
if (app.globalData.driverState === 0) {
clearInterval(that.data.interval)
clearInterval(that.data.interval2)
}
}, 5000)
},