vue3 toRef ,toRefs ,isRef ,unref属性

   // toRef ,toRefs ,isRef ,unref属性
   // toRef:转化为ref
    const torNum = toRef(states,'num')
    console.log(torNum.value) //5
    
    // isRef 判断是否为ref对象
    const info = ref({name :'名字',info:{age:18,height:1111,}})
    const infos = {name :'名字',info:{age:18,height:1111, }}
    console.log(isRef(info)) // true
    console.log(isRef(infos)) // false

    console.log(unref(info)) // Proxy {name: '名字', info: {}}
    console.log(unref(infos))//       {name: '名字', info: {}}
 
    // isRef(info)?info.value:'info'  等同unref(info)
    //toRefs 数据return 出去 ...toRefs()

你可能感兴趣的:(vue)