【发布时间】:2022-01-06 21:31:29
【问题描述】:
考虑以下(简化的)商店。它包含一个“笔记”(类对象)数组:
// store.ts
import { reactive } from 'vue'
import { Note } from 'src/lib/note'
class Store {
allNotes: Note[] = []
}
export const store = reactive(new Store())
我想关注allNotes 的变化:
// note.ts
import { store } from 'src/lib/store'
watch(store.allNotes,
(oldVal, newVal) => _.difference(newVal, oldVal)
.forEach(note => {
console.log("note changed")
}),
{deep: true}
)
当更改特定注释(store.allNotes 元素的属性)时,我确实在 Chome DevTools Vue 中看到了更改,但我的手表没有触发。为什么?
【问题讨论】: