wachtEffect()
- watch的套路是:既要指明监听的属性,也要指明监听的回调
- watchEffect的套路是: 不用指明监听哪个属性,监听的回调中用到哪个属性,那就监视哪个属性。
const todoId = ref(1)
const data = ref(null)
watch(todoId, async () => {
const response = await fetch(
`https://jsonplaceholder.typicode.com/todos/${todoId.value}`
)
data.value = await response.json()
}, { immediate: true })
小于 1 分钟