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)   }) })

完整代码

   

相关内容

热门资讯

中科天玑携“社会认知大脑”亮相... 2025-12-10 17:43:27 作者:狼叫兽 近日,第五届网络空间内生安全学术大会在南京隆...
苹果M5 MacBook Pr... 今年 10 月 16 日,苹果在线商店悄然上架了三款新品,MacBook Pro、iPad Pro ...
首届山东省未来产业创新创业大赛... 通讯员 于龙 刘琰玮 近日,首届山东省未来产业创新创业大赛决赛在泰安高新区举办,31支晋级队伍围绕未...
打造湾区“空中纽北”!深圳市大... 南都讯 12月10日,深圳市大鹏新区无人机测试基地正式启用。记者在现场获悉,该基地是深圳市“1+5+...
怀柔团区委组织青少年参加“学宪... 为充分发挥共青团在青少年普法教育与安全自护领域的重要作用,切实提升青少年法治素养和自我保护能力,近日...