2025-04-27 vue3.5 版本新增特性

只记录常用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)
})
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容