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

完整代码

   

相关内容

热门资讯

一分钟了解!牛牛房卡出售荣耀乐... 您好!微信荣耀乐娱大厅链接获取房卡可以通过以下几种方式购买: 1.微信渠道:(荣耀乐娱)大厅介绍:...
玩家攻略,金花充值房卡海豚大厅... 海豚大厅是一款非常受欢迎的棋牌游戏,咨询房/卡添加微信:【3329006910】或33549083许...
正规平台有哪些,牛牛房卡制作链... 正规平台有哪些,牛牛房卡制作链接红桃众娱/房卡微信链接红桃众娱是一款非常受欢迎的游戏,咨询房/卡添加...
科技实测!金花房间怎么创建天狗... 科技实测!金花房间怎么创建天狗大厅/微信链接房卡销售购买天狗大厅是一款非常受欢迎的游戏,咨询房/卡添...
重大通报,牛牛房卡出售番茄大厅... 重大通报,牛牛房卡出售番茄大厅/房卡最低良心价售Sa9Ix苹果iPhone 17手机即将进入量产阶段...