1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
| <template> <div class="person"> <h2>当前求和为:{{sum}}</h2> <button @click="add">点击</button> </div> </template>
<script lang="ts" setup> defineOptions({ name: 'person5' }) import { ref ,onBeforeMount,onMounted,onBeforeUpdate, onUpdated,onBeforeUnmount,onUnmounted} from 'vue' //数据 let sum = ref(0)
//方法 function add() { sum.value+=1 }
//创建 console.log('创建')
//挂载前 onBeforeMount(() => { console.log('挂载前') }) //挂载完毕 onMounted(() => { console.log('挂载完毕') }) //更新前 onBeforeUpdate(() => { console.log('更新前') }) //更新完毕 onUpdated(() => { console.log('更新完毕') }) //卸载前 onBeforeUnmount(() => { console.log('卸载前') }) //卸载完毕 onUnmounted(() => { console.log('卸载完毕') })
</script>
<style scoped> .person{ background-color: aqua; box-shadow: 0 0 10px; border-radius: 10px; padding:20px; } </style>
|