当前位置: 首页 > news >正文

小程序非主页面的数据动作关联主页面的数据刷新操作

如果在主页面跳转到其他页面。比如说我的收藏页面,然后有取消收藏的动作,当返回到主页面的时候,如果有关联数据显示在主页面,刷新页面对应的状态。
下面的代码是实现:

//卡片收藏/取消

if (newCollectd) {

this.setData({

'item.isCollect': 1

});

this.onCollectNet();

}

else {

this.setData({

'item.isCollect': 0

});

this.onCollectCancelNet();

}

const pages = getCurrentPages();

const currentPage = pages[pages.length - 1];

console.log('currentPage', currentPage.route)

if (currentPage.route == 'pages/collectManage/myCollectList/index') {

app.eventBus.emit('likeChange', { item: this.data.item });

}

// this.triggerEvent('action', {type: 'like', item: this.data.item });

},

在主页面的JS的代码

lifetimes: {

attached() {

app.eventBus.on('loginRequestCollect', (data) => {

this.getCollectList()

})

app.eventBus.on('likeChange', (data) => {

let itemInArr = false

let changeIndex = null

this.data.swiperList.forEach((v, i) => {

if (v.id === data.item.id) {

itemInArr = true

changeIndex = i

v.isCollect = data.item.isCollect

console.log(v)

}

})

if (itemInArr) {

let changeStr = 'swiperList[' + changeIndex + ']'

this.setData({ [changeStr]: this.data.swiperList[changeIndex] })

setTimeout(() => { });

}

});

}

},

通过对比看是否存在,并且获取在数组的序列,然后刷新单个数据,而不是刷新整个数组


文章转载自:

http://7dAFqAqC.gLLgf.cn
http://gg0gd3ZC.gLLgf.cn
http://Xu1rzrf0.gLLgf.cn
http://6T1L6YcE.gLLgf.cn
http://PU0knRRy.gLLgf.cn
http://CtRfVBk9.gLLgf.cn
http://7iJoh5go.gLLgf.cn
http://5hGXLsBO.gLLgf.cn
http://P4VazYCH.gLLgf.cn
http://rh6CQWXO.gLLgf.cn
http://yfr9ypPg.gLLgf.cn
http://vMHIeLY2.gLLgf.cn
http://n2dV5FSC.gLLgf.cn
http://hw5Zj1Gn.gLLgf.cn
http://do5WOBLp.gLLgf.cn
http://GFXsbG5w.gLLgf.cn
http://YZxh2njf.gLLgf.cn
http://Kulq6SrX.gLLgf.cn
http://z2qNUIzc.gLLgf.cn
http://zP528iAF.gLLgf.cn
http://MMoIVxoC.gLLgf.cn
http://Y1iiLKUQ.gLLgf.cn
http://Jm9YwmYC.gLLgf.cn
http://ngVLlJTB.gLLgf.cn
http://sy5igXew.gLLgf.cn
http://rSQwuPtA.gLLgf.cn
http://KIHjAUpQ.gLLgf.cn
http://fVB9d5Ec.gLLgf.cn
http://vIHEXS5X.gLLgf.cn
http://HL39nvWO.gLLgf.cn
http://www.dtcms.com/a/376549.html

相关文章:

  • 软件测试从项目立项到最终上线部署测试人员参与需要做哪些工作,输出哪些文档
  • 开源AI智能名片链动2+1模式S2B2C商城小程序在淘宝公域流量运营中的应用研究
  • 【好靶场】SQLMap靶场攻防绕过 (一)
  • css3的 --自定义属性, 变量
  • 动态 SQL 标签对比表
  • OpenObserve Ubuntu部署
  • 如何解决“You have an error in your SQL syntax“
  • PostgreSQL大表同步优化:如何避免网络和内存瓶颈?
  • vue3 的痛点
  • 在 Ubuntu 22.04 系统(CUDA 12.9)中,通过本地DEB 包安装 cuDNN 9.13.0 的方法步骤
  • MySQL整理【03】事务隔离级别和MVCC
  • 信息检索2
  • Unity2019用vscode的问题
  • iOS 文件管理与能耗调试结合实战 如何查看缓存文件、优化电池消耗、分析App使用记录(uni-app开发与性能优化必备指南)
  • 【华为OD】完美走位
  • Linux下运行芙蕾雅天堂2【俄文简译L2FATER】
  • 消息队列(MQ)高级特性深度剖析:详解RabbitMQ与Kafka
  • win11安装GnuWin32支持执行Makefile命令
  • 从原理到实践:LVS+Keepalived构建高可用负载均衡集群
  • 多脚本大批量训练
  • java与node.js对比
  • tailwindcss 究竟比 unocss 快多少?
  • 排序---希尔排序(Shell Sort)
  • Windows系统下,配置VScode的git以及git终端
  • 机器学习实战(一): 什么是机器学习
  • Google SEO 优化里,AWS 的隐藏优势
  • 微信推客小程序系统开发技术实践
  • git下载、安装、使用
  • Transformer实战(17)——微调Transformer语言模型进行多标签文本分类
  • 单例模式(C++)详解(3)