只记录常用api的变动
1:Props 解构新写法
带默认值
const { count = 0, msg = 'hello' } = defineProps<{count?: number; message?: string}>()
不带默认值
const { count , msg = 'hello' } = defineProps<{count?: number; message?: string}>()
2:获取dom引用
使用useTemplateRef替代ref
<script setup>
import { useTemplateRef } from 'vue'
const inputRef = useTemplateRef('input')
</script>
<template>
<input ref="input" />
</template>
3:onWatcherCleanup
新增清理watch副作用的方法,解决频繁调用副作用的问题
import { watch, onWatcherCleanup } from 'vue'
watch(id, (newId) => {
const { response, cancel } = doAsyncWork(newId)
// 如果 `id` 变化,则调用 `cancel`,
// 如果之前的请求未完成,则取消该请求
onWatcherCleanup(cancel)
})