页面中有一组Switch组件,默认全部开启,通过改变switchValue控制开关
开关数据从一个常量文件中导入的
export const stationStatusSwitch = [
{
switchValue: true,
id: 1
},
{
switchValue: true,
id: 2
},
{
switchValue: true,
id: 3
},
{
switchValue: true,
id: 4
},
{
switchValue: true,
id: 5
},
{
switchValue: true,
id: 6
},
{
switchValue: true,
id: 7
}
]
import { stationStatusSwitch } from "./constants";`
constructor(props) {
this.state = {
stationStatusSwitch,
}
}
现在有个问题就是:如果把开关关闭也就是switchValue设为false然后再回到上个页面再重新进入这个页面,这个时候开关还是关闭的,switchValue的值还是false,在class外边打印stationStatusSwitch发现switchValue也是false。
这个就不明白了,回到上个页面再进入这个页面,state不应该被重置吗,我改变的是state为什么还是影响到导入的数组。如果我把stationStatusSwitch放到当前页面的state中就不会有这个问题,
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…