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

完整代码

   

相关内容

热门资讯

科普必备“微信群好友房炸金花房... 微信游戏中心:炸金花房卡,添加微信【33699510】,进入游戏中心或相关小程序,搜索“微信炸金花房...
科普必备“微信牛牛房卡链接充值... 牛牛是一款非常受欢迎的棋牌游戏,咨询房/卡添加微信:33699510许多玩家在游戏中会购买房卡来享受...
科普必备“六人拼三张房卡怎么购... 微信游戏中心:拼三张房卡,添加微信【33699510】,进入游戏中心或相关小程序,搜索“微信拼三张房...
科普必备“牛牛房卡如何购买-新... 牛牛是一款非常受欢迎的棋牌游戏,咨询房/卡添加微信:33699510许多玩家在游戏中会购买房卡来享受...
科普必备“炸金花房卡找谁购买,... 微信游戏中心:拼三张房卡,添加微信【33699510】,进入游戏中心或相关小程序,搜索“微信拼三张房...