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

完整代码

   

相关内容

热门资讯

分析教程!微信怎么建房玩斗牛牛... 拼三张是一款非常受欢迎的棋牌游戏,咨询房/卡添加微信:82606316许多玩家在游戏中会购买房卡来享...
分析教程!微信玩牛牛房间链接,... 微信游戏中心:牛牛房卡,添加微信【82606316】,进入游戏中心或相关小程序,搜索“微信牛牛房卡”...
分析教程!斗牛好友房卡在哪购买... 斗牛是一款非常受欢迎的棋牌游戏,咨询房/卡添加微信:82606316许多玩家在游戏中会购买房卡来享受...
分析教程!微信房卡斗牛链接怎么... 微信游戏中心:斗牛房卡,添加微信【82606316】,进入游戏中心或相关小程序,搜索“微信斗牛房卡”...
分析教程!炸金花链接房间从哪里... 炸金花是一款非常受欢迎的棋牌游戏,咨询房/卡添加微信:82606316许多玩家在游戏中会购买房卡来享...