vue3 watch监听多个数据

第一个参数返回ref数组即可

<script setup lang="ts">
  const cnt1 = $ref(0)
  const cnt2 = $ref(0)

  watch(() => [cnt1, cnt2], () => console.log(cnt1, cnt2))
</script>

<template>
  <div>
    <button btn @click="cnt1++">cnt1+</button>
    {{cnt1}}
    <button btn @click="cnt2++">cnt2+</button>
    {{cnt2}}
  </div>
</template>

posted @ 2022-06-10 13:13  七つ一旋桜  阅读(904)  评论(0)    收藏  举报