Skip to content

watch问题

watch cb中包含复杂函数

js

setup(){
  const func = () => {
    setTimeout(() => {
      console.log('------ ztimmasd 22-------')
    }, 10)
  }
  watch(() => [pageInfo.page], () => {
      func() // 这是不会执行的
  })
}

修改成

js
setup(){
  const func = () => {
    setTimeout(() => {
      console.log('------ ztimmasd 22-------')
    }, 10)
  }
  watch(() => [pageInfo.page], func)
}