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

完整代码

   

相关内容

热门资讯

低调霸榜全球最难SQL榜单超两... 来源:市场资讯 (来源:量子位) 不鸣则已,一鸣惊人。 没想到一个低调霸榜了全球最权威SQL榜单超过...
2025深圳搬家公司品牌排行榜... 凌晨三点的深圳宝安工业园,某电子厂的车间里依然灯火通明。厂长王建军盯着地上价值800万的数控加工中心...
文远知行和Uber在迪拜推出R... 【CNMO科技消息】近日,文远知行通过Uber App向公众提供Robotaxi出行服务,率先覆盖乌...
2025年最全电信电话卡攻略:... 办卡关注 微 信 公 众 号 :找卡乐园 这里是专为你打造的流量卡服务站,既能帮你揭开流量卡市场的各...
“以AI守护AI” 为守护大模... 天津北方网讯:近日,由中央网络安全和信息化委员会办公室、国家市场监督管理总局共同指导的“第十五届网络...