<template>
<div>
watch监听ref属性值:{{a}}
<el-button type="primary" @click="plusFn">ref加1</el-button>
</div>
<div>
watch监听reactive属性值:{{b}}
<el-button type="primary" @click="plus1Fn">reactive加1</el-button>
</div>
<div>

</div>
</template>
<script>
import { defineComponent,reactive,ref,watch } from 'vue'

export default defineComponent({
setup() {
let a = ref(10)
let b = reactive({age:1})
watch(a, ()=>{
console.log(a.value)
})
let plusFn=()=>{
a.value++
}
let plus1Fn=()=>{
b.age++
}
watch(()=>b.age, (newVal, oldVal,clear)=>{
console.log(newVal, oldVal,clear)
})
return{
a,
plusFn,
plus1Fn,
b
}
},
})
</script>
<style scoped>

  

相关文章:

  • 2022-12-23
  • 2023-03-21
  • 2022-12-23
  • 2021-06-02
  • 2022-12-23
  • 2021-07-30
猜你喜欢
  • 2022-12-23
  • 2021-12-07
  • 2021-05-16
  • 2022-12-23
  • 2023-01-20
  • 2021-07-11
  • 2021-11-11
相关资源
相似解决方案