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

完整代码

   

相关内容

热门资讯

比亚迪第1500万辆新能源车下... “我们要做一道证明题,证明比亚迪可以,证明新能源可以,证明中国汽车可以。” 文章开篇,让我们把记忆首...
2025手机三国杀:小米涨价了... “透视图”栏目在年终特别策划了“36氪年度总结”系列,用数据透视2025全年趋势,以图片呈现今年商业...
零点有数洞察:人工智能赋能新消... 当一款不知名的吹风机在三年内跃居行业第二,当一桶鸭脖因击中情绪密码而月销百万,当一瓶饮料能像软件一样...
硬核跨年!张朝阳再启物理演讲,... 12月31日,搜狐创始人、董事局主席兼首席执行官、物理学博士张朝阳的2026跨年演讲即将硬核开启。这...
联想回应与字节AI手机合作:“... IT之家 12 月 19 日消息,今天下午,针对字节跳动与硬件厂商开展 AI 手机合作的消息,联想方...