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

完整代码

   

相关内容

热门资讯

国家网信办起草新规禁止APP偷... 中新社北京1月10日电 (记者 刘育英)中国国家互联网信息办公室10日就《互联网应用程序个人信息收集...
“死了么”登顶App Stor... IT之家 1 月 11 日消息,1 月 8 日起,一款名为“死了么”的应用在苹果 App Store...
追觅闪耀CES 2026:全屋... 2026年1月9日,全球消费电子领域顶级盛会CES 2026在美国拉斯维加斯圆满收官。全球高端科技品...
OpenAI和软银将向SB E... 1月10日消息,OpenAI与软银于宣布,双方将向SB Energy投资10亿美元,以支持OpenA...
美团、淘宝闪购、京东集体表态! 1月9日,国务院反垄断反不正当竞争委员会办公室宣布,对外卖平台服务行业市场竞争状况开展调查、评估。对...