在页面栈内有两个页面共用了同一个组件,在激活当前页面
page[4](podcast/pages/user/interact/interact)的组件,
并修改了相关数据后,再返回
page[2] (podcast/pages/interact/interact)时,
page[2] 的数据也同时被修改了。
请问如何保证不修改 page[2] 数据?
测试了一下 properties 对象,发现了个奇怪的现象:
这是 page2
这是 page4
这是 page4 返回 page2 后的数据变化
pageLifetimes: {
show: function () {
if (this.data.path != "Profile") {
console.log("properties / show", this.properties.audio);
innerAudioContext = wx.createInnerAudioContext({
useWebAudioImplement: true,
});
timer = new Timer();
const { duration, url } = this.properties.audio;
innerAudioContext.src = url;
this.data._audio = this.properties.audio;
this.setData({ max: duration });
this.easyTimer.bind(this)();
}
},
hide: function () {
console.log("hide");
timer.removeAllEventListeners();
innerAudioContext.destroy();
}
},
一般来说组件内的属性是不会串的。可能是组件内修改数据的变量式非
data
内声明的属性(state
),比如说是在外部var
的变量。或者是全局变量之类的。然后确定
page[2]
页面对应属性值获取方式,是否在生命周期内做了setState
操作,重新赋值就有可能会显示修改后的数据。其实你把问题描述的更加详细一些,这样更加好回答,比如说公用组件脱敏后的业务逻辑。