Vue3.5与Vue3新功能对比
创始人
2024-09-25 04:49:45

一、props解构,默认值

vue3

const { count = 0, message = 'hello' } = withDefaults(   defineProps<{     count?: number     message?: string   }>(),   {     count: 0,     message: 'hello'   } )

vue3.5 

const { count = 0,message = 'hello'} =  defineProps<{   count?: number;   message?: string; }>()

二、useId

全局唯一id-----一个app内 

const id = useId()

三、useTemplateRef

通过ref获取dom

vue3

const button = ref(null)

vue3.5 

const el = useTemplateRef('button') console.log(el, 'dom')

四、watch新增 onCleanup回调

vue3.5

onCleanup---下一次watch执行前触发---可以在这里移除上一次watch

watch(count, (newVal, oldVal, onCleanup) => {   const handler = () => {     console.log(newVal, 'newVal')   }   addEventListener('click', handler)   onCleanup(() => {     removeEventListener('click', handler)   }) })

完整代码

   

相关内容

热门资讯

发布资讯搜不到?快来看互联网收... “发布后的品牌资讯、企业动态百度搜不到;优质的品牌或产品信息在AI问答里从未被引用;朋友圈转发的品牌...
航天动力:仅配合加工火箭发动机... 12月8日,航天动力(600343.SH)发布股票交易风险提示性公告,公司股票于2025年12月5日...
首款搭载Gemini的AI眼镜... 谷歌正通过Android XR平台和Gemini AI的深度整合,在智能眼镜领域发起新一轮进攻。 谷...
早安,高新 | 国内首台GaN... 新闻摘要 国内首台GaN动态参数测试系统成功交付 智象未来获评“年度最具商业潜力企业” 高新区举办集...
原创 为... 当得物App数据显示iPhone17标准版首日销量超越Pro机型时,整个手机圈都嗅到了反常的气息。更...