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

完整代码

   

相关内容

热门资讯

收盘丨沪指涨0.47%录得7连... 12月25日,A股三大指数午后集体翻红,截至收盘,沪指涨0.47%,深成指涨0.33%,创业板指涨0...
人民网联合游族网络成立AI交互... 人民网与游族网络共同为AI交互语料创新实验室揭牌 人民网上海12月25日电 12月25日,由人民网、...
智能设备可追溯药品源头、AI算... 东方网记者程琦12月25日报道: “市面上流通的3支医美针剂里,可能只有1支是正品。”当这组出自专业...
永康市泓越工贸取得电动吸盘专利... 国家知识产权局信息显示,永康市泓越工贸有限公司取得一项名为“一种电动吸盘”的专利,授权公告号CN22...
广电卡套餐真实体验:性价比超高... 办卡:微 信 公 众 号 搜【 可可 找卡】,每天更新运营商官方高性价比套餐!帮你精准匹配适配流量方...