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

完整代码

   

相关内容

热门资讯

玩家知识!炸金花好友房卡在哪里... 微信游戏中心:炸金花房卡,添加微信【66336574】,进入游戏中心或相关小程序,搜索“微信炸金花房...
全程科普!炸金花在哪买房卡,微... 微信游戏中心:拼三张房卡,添加微信【33903369】,进入游戏中心或相关小程序,搜索“微信拼三张房...
记者手记|AI防AI:守卫金融... 新华社新加坡11月15日电 记者手记|AI防AI:守卫金融安全的新前线 新华社记者舒畅 斯里兰卡DM...
玩家知识!我买微信牛牛房卡链接... 微信游戏中心:牛牛房卡,添加微信【56001354】,进入游戏中心或相关小程序,搜索“微信牛牛房卡”...
全程科普!微信群发链接牛牛房卡... 微信游戏中心:拼三张房卡,添加微信【55051770】,进入游戏中心或相关小程序,搜索“微信拼三张房...