useList.js:
import { ref, onMounted, watchEffect } from 'vue'
const useList = () => {
const count = ref(0)
watchEffect(() => {
console.log(count.value)
})
const handleClick = () => {
count.value++
}
onMounted(() => {
console.log(1)
})
return {
count,
handleClick,
}
}
export default useList
参考链接:
https://cn.vuejs.org/api/reactivity-core.html#watcheffect
人工智能学习网站