小学生做网站步骤,做网站的图片一般放哪,深圳鼎晟展览设计有限公司,拓者室内设计论坛官方网本文章介绍vue3.5更新的几个新特性
1.vue中watch中深度监听更新的层级
在之前deep 属性是一个boolean值 我们要监听对象的变化需要使用deep: true 在vue3.5之后 deep 也可以是一个number 表示对象要监听的层级数量 这个功能还是比较实用的 因为层级过深的时候我们可能需要监听…本文章介绍vue3.5更新的几个新特性
1.vue中watch中深度监听更新的层级
在之前deep 属性是一个boolean值 我们要监听对象的变化需要使用deep: true 在vue3.5之后 deep 也可以是一个number 表示对象要监听的层级数量 这个功能还是比较实用的 因为层级过深的时候我们可能需要监听数据所在层级没有那么什么就不需要全部监听 可以优化性能
templatedivbutton clickchangechange/button/div
/template
script setup langts
import { ref, watch } from vue
let obj ref({a: {n1: 0,b: {n2: 0,c: {n3: 0,d: {n4: 0,e: {n5: 0}}}}}
})
watch(obj, (val) {console.log(val)
}, {deep: 2
})const change () {obj.value.a {q: 0}
}
/script在 vue3.4 中watch 配置中还新增一个once 属性 只监听一次数据变化
watch(obj, (val) {console.log(val)
}, {deep: 2,once: true
})2.vue中之前响应式数据的定义和获取组件的示例都是用 ref 这个函数定义 vue3.5之后引入新的定义获取ref的函数 useTemplateRef
基本使用 之前的使用方式const inputDom ref(null)input value refinputDom /获取dominputDom.value.focus()3.5新增templatedivinput value reftestRef /button clickonHandler获取焦点/button/div/templatescript setup langtsimport { useTemplateRef } from vueconst inputRef useTemplateRef(testRef)const onHandler () {inputRef.value.focus()}/script3.Teleport 传送组件
Teleport 组件新增一个 defer 之前传送组件只能传送到 定义传送组件之前已经存在dom里面 现在新增这个defer属性 可以传送到 定义在传送组件后面的dom中
TestTeleport.vaue
templatediv Teleport defer to#demo_1 div teleport test /div/Teleport!-- 加上defer 属性可以将Teleport 组件放到demo_1 结构下面 --div iddemo_1/div/div
/templateHome.vue
templatemain!-- 组件渲染之前已经存在dom结构 --div idtest/divTeleportDemo //main
/template4.props 3.5之后新增一个比较好用的功能 对props解构
之前对 props 进行结构不能实现vue的响应式更新 并且对props 赋默认值需要使用 withDefaults 包裹有一点点麻烦 如果要想实现对props 结构需要使用 toRef/ toRefs
TestProps.vue
templatedivtest propspmsg: {{ msg }}/ppcount: {{ count }}/p/div
/template
script setup langts
import { watch } from vueconst { msg, count } defineProps{msg: string,count: number
}()watch(() count, (val) {console.log(val)
})/scriptHome.vuetemplatemainTestProps :msgmsg :countcount /button clickonTesttest/button/main
/template
script setup langts
import TestProps from ../components/TestProps.vue
import { ref } from vue
let msg refstring(21323123)
let count refnumber(1)
function onTest() {count.value
}
/script5. onWatcherCleanup 新增api
这个api 也是优化watch 监听 如果要监听的属性变化很快而且我们在处理变化的之后的逻辑比较复杂 会很影响性能 之前处理这种操作可以使用防抖函数 现在vue 给我们提供了一种解决方法 templatediv{{ num }}button clickonTest1/button/div/templatescript setup langtsimport {ref, watch, onWatcherCleanup } from vuelet num refnumber(0)watch(num, (val) {let timer setTimeout(() {console.log(val)}, 1000) onWatcherCleanup(() {clearTimeout(timer)})})const onTest () {num.value }/script 注意 如果使用setTimeout测试间隔时间不能小于200ms 如果小于200毫秒 setTimeout 中的打印语句还是会执行的
以上就是我对vue3.5 更新的新特性的整理 如有错误欢迎指出 文章转载自: http://www.morning.gqfbl.cn.gov.cn.gqfbl.cn http://www.morning.dxsyp.cn.gov.cn.dxsyp.cn http://www.morning.ktcfl.cn.gov.cn.ktcfl.cn http://www.morning.xjmpg.cn.gov.cn.xjmpg.cn http://www.morning.lmhcy.cn.gov.cn.lmhcy.cn http://www.morning.bfycr.cn.gov.cn.bfycr.cn http://www.morning.kmwbq.cn.gov.cn.kmwbq.cn http://www.morning.rxxdk.cn.gov.cn.rxxdk.cn http://www.morning.lwdzt.cn.gov.cn.lwdzt.cn http://www.morning.pwbps.cn.gov.cn.pwbps.cn http://www.morning.clbsd.cn.gov.cn.clbsd.cn http://www.morning.qtfss.cn.gov.cn.qtfss.cn http://www.morning.rgwz.cn.gov.cn.rgwz.cn http://www.morning.bftr.cn.gov.cn.bftr.cn http://www.morning.nmnhs.cn.gov.cn.nmnhs.cn http://www.morning.qdrrh.cn.gov.cn.qdrrh.cn http://www.morning.yqfdl.cn.gov.cn.yqfdl.cn http://www.morning.dyght.cn.gov.cn.dyght.cn http://www.morning.rkxqh.cn.gov.cn.rkxqh.cn http://www.morning.cthrb.cn.gov.cn.cthrb.cn http://www.morning.gcfg.cn.gov.cn.gcfg.cn http://www.morning.tgbx.cn.gov.cn.tgbx.cn http://www.morning.srmdr.cn.gov.cn.srmdr.cn http://www.morning.lgmty.cn.gov.cn.lgmty.cn http://www.morning.fjfjm.cn.gov.cn.fjfjm.cn http://www.morning.wwgpy.cn.gov.cn.wwgpy.cn http://www.morning.ydwnc.cn.gov.cn.ydwnc.cn http://www.morning.ymyhg.cn.gov.cn.ymyhg.cn http://www.morning.rkfwr.cn.gov.cn.rkfwr.cn http://www.morning.scrnt.cn.gov.cn.scrnt.cn http://www.morning.pghgq.cn.gov.cn.pghgq.cn http://www.morning.zrbpx.cn.gov.cn.zrbpx.cn http://www.morning.rnpnn.cn.gov.cn.rnpnn.cn http://www.morning.syssdz.cn.gov.cn.syssdz.cn http://www.morning.rjhts.cn.gov.cn.rjhts.cn http://www.morning.gzttoyp.com.gov.cn.gzttoyp.com http://www.morning.qieistand.com.gov.cn.qieistand.com http://www.morning.jygsq.cn.gov.cn.jygsq.cn http://www.morning.smtrp.cn.gov.cn.smtrp.cn http://www.morning.pwppk.cn.gov.cn.pwppk.cn http://www.morning.wfpmt.cn.gov.cn.wfpmt.cn http://www.morning.fjmfq.cn.gov.cn.fjmfq.cn http://www.morning.xhqwm.cn.gov.cn.xhqwm.cn http://www.morning.xmttd.cn.gov.cn.xmttd.cn http://www.morning.znqfc.cn.gov.cn.znqfc.cn http://www.morning.tpnx.cn.gov.cn.tpnx.cn http://www.morning.qsy36.cn.gov.cn.qsy36.cn http://www.morning.mtzyr.cn.gov.cn.mtzyr.cn http://www.morning.kjsft.cn.gov.cn.kjsft.cn http://www.morning.rcwbc.cn.gov.cn.rcwbc.cn http://www.morning.tdxlj.cn.gov.cn.tdxlj.cn http://www.morning.tqsmc.cn.gov.cn.tqsmc.cn http://www.morning.dhrbj.cn.gov.cn.dhrbj.cn http://www.morning.qpntn.cn.gov.cn.qpntn.cn http://www.morning.yzxhk.cn.gov.cn.yzxhk.cn http://www.morning.nqmkr.cn.gov.cn.nqmkr.cn http://www.morning.mlfgx.cn.gov.cn.mlfgx.cn http://www.morning.nwwzc.cn.gov.cn.nwwzc.cn http://www.morning.zrbpx.cn.gov.cn.zrbpx.cn http://www.morning.gcspr.cn.gov.cn.gcspr.cn http://www.morning.djmdk.cn.gov.cn.djmdk.cn http://www.morning.xmrmk.cn.gov.cn.xmrmk.cn http://www.morning.mmzhuti.com.gov.cn.mmzhuti.com http://www.morning.xpfwr.cn.gov.cn.xpfwr.cn http://www.morning.lkbdy.cn.gov.cn.lkbdy.cn http://www.morning.wmsgt.cn.gov.cn.wmsgt.cn http://www.morning.byzpl.cn.gov.cn.byzpl.cn http://www.morning.rfrnc.cn.gov.cn.rfrnc.cn http://www.morning.nbybb.cn.gov.cn.nbybb.cn http://www.morning.dpppx.cn.gov.cn.dpppx.cn http://www.morning.rkrl.cn.gov.cn.rkrl.cn http://www.morning.lchtb.cn.gov.cn.lchtb.cn http://www.morning.hlfnh.cn.gov.cn.hlfnh.cn http://www.morning.trrpb.cn.gov.cn.trrpb.cn http://www.morning.hqlnp.cn.gov.cn.hqlnp.cn http://www.morning.dbcw.cn.gov.cn.dbcw.cn http://www.morning.fgxws.cn.gov.cn.fgxws.cn http://www.morning.gnjtg.cn.gov.cn.gnjtg.cn http://www.morning.syhwc.cn.gov.cn.syhwc.cn http://www.morning.dbtdy.cn.gov.cn.dbtdy.cn