# 监听数据的变化有两种方法
1.方法1 利用computed 如果属性变化了模版里的数据也会跟着刷新的
<div :data-currentTime="currentTime">
<div>{{text(time)}}</div>
</div>
let time = ref(new Date().getTime())
const currentTime = computed(() => {
return store.state.currentTime;
});
const text = (data)=>{
return data
}
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
- 方法2 利用watch监听
watch(store.state.currentTime, (newVal) => {
console.log(newVal)
})
1
2
3
2
3