1.响应式内部源码优化
2.Props的解构
const { message = "默认值message", count = 0 } = defineProps({
message:String,
count: Number
})
watch( () => count, (newV) => {
console.log("count发生变化",newV)
})
3.SSR优化
4.自定义元素改善
5.其他相关特性
<input type="text" ref="customKey">
<button @click="focus">获取焦点</button>
import { useTemplateRef } from "vue"
const inputRef = useTemplateRef("customKey")
const focus = () => {
inputRef.value.focus()
}
<Teleport defer to="#targetEl">
<div>挂载的的内容</div>
</Teleport>
<div id="targetEl"></div>
<button @click="id++">id 改变</button>
import {ref,watch,onWatcherClearup} from "vue"
const id = ref(0)
watch(id,(newV)=>{
const timer = setTimeOut(()=>{
console.log("根据id获取的结果",newV)
},2000)
onWatcherClearup(()=>{
clearTime(timer)
})
})