微信小程序修改数据不刷新页面更新数据

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_38543537/article/details/85448736

先将数据储存到本地缓存,如下:

wx.setStorageSync('caseid', this.data.id)
wx.setStorageSync('newmsg', data) //data是一个对象

在需要修改的页面获取本地缓存的数据,如下:

var newmsg = wx.getStorageSync('newmsg')
var caseid = wx.getStorageSync('caseid')

将获取到的本地缓存数据通过对比ID判断更改哪一个列表的数据,如下:

let list = this.data.anliList;//这里是将需要循环的数组赋值给list
  // 将本地缓存数据渲染到对应修改的案例
list.forEach(function (value,index, array){
  console.log(array[index].id)
  if (array[index].id == caseid) {
     array[index].cover = newmsg.cover;
     array[index].name = newmsg.name;
     array[index].tags = newmsg.tags;
     array[index].color = newmsg.color;
     array[index].price = newmsg.price;
     console.log(array[index].cover)
     console.log(array[index].name)
    }
})
this.setData({
  anliList: list
})

猜你喜欢

转载自blog.csdn.net/qq_38543537/article/details/85448736