Vue的高阶特性
-
toRefs (对reactive进行解构)
-
watch侦听器
-
watch(()=>属性,(currentValue, preValue)=>{
//相应业务
console.log('现在的:', currentValue)
console.log('之前的', preValue)
})
-
-
特点:(1)有惰性
(2)更加具体
(3)可以访问属性之前的值
(4)可配置的 <非惰性, 深度监视>
watch( brand, (currentValue, preValue)=>{
//相应业务
console.log('现在的:', currentValue)
console.log('之前的', preValue)
}, {
//非惰性
//immediate : true
deep: true
})
-
第二种watch:
- 非惰性
- 更加抽象
- 不可以访问属性之前的值(只能获取当前属性的最新值)适合一对多
- 可配置<非惰性, 深度监视>
-
watchEffect( ()=>{
console.log('开始监听了!......')
})
provide inject
provide 发射
provide('brand',readonly(brand))
provide('changeBrand',changeBrand)
const changeBrand = (params) => {
brand.value = params
}
const bName =inject('brand', '默认值')
const changeBrand = inject('changeBrand')
const changeName = () =>{
changeBrand()
}
<button @click="changeName">改变值