vue 关于deep watch / computed 监听不到 vuex state 对象变化的的问题

时间:2023-03-09 16:10:50
vue 关于deep watch / computed 监听不到 vuex state 对象变化的的问题

简而言之,如果vuex state 中是一个对象 {},那么监听就会有问题。先给出解决方案:

// 超简易拷贝(如果是深拷贝还多此一举把get/set拷贝进去了,所以用简易拷贝即可)
let __VALUE__ = JSON.parse(JSON.stringify(state.problemReply))
// 加入部门回复详情
__VALUE__[orderId] = data.problemReply
// 更新,只能这样一波骚操作才能让computed和watch监听到。具体原因我稍后学习o(╥﹏╥)o。
state.problemReply = __VALUE__