首页 > 其他 > 详细

vue3.0---watch使用方法

时间:2021-07-02 00:52:21      阅读:25      评论:0      收藏:0      [点我收藏+]
<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>

  

vue3.0---watch使用方法

原文:https://www.cnblogs.com/xinheng/p/14959877.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!