watch监听ref的简单类型

<template>
  <div>
    {{refWatch}}
    <button @click="refWatch++">ref的变化</button>
  </div>
</template>

<script>

import {ref,reactive,watch} from 'vue'

export default {

  setup(){
    // 1.ref的监听 - 简单数据
    const refWatch = ref(0)

    watch(refWatch,(newV,oldV)=>{
      console.log(newV,oldV)
    })

    return {
      refWatch,
    }
  }
}
</script>

 

posted @ 2022-08-24 15:43  杨建鑫  阅读(250)  评论(0编辑  收藏  举报