vue3.0---watch使用方法

<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使用方法

上一篇:(九)unity4.6学习Ugui中文文档-------參考-UGUI Rect Transform


下一篇:Educational Codeforces Round 73 (Rated for Div. 2)