vue3 toRefs()函数用法
作者:互联网
function isReactive(value) {
if (isReadonly(value)) {
return isReactive(value["__v_raw" /* RAW */]);
}
return !!(value && value["__v_isReactive" /* IS_REACTIVE */]);
}
function isReadonly(value) {
return !!(value && value["__v_isReadonly" /* IS_READONLY */]);
}
function isProxy(value) {
return isReactive(value) || isReadonly(value);
}
const isArray = Array.isArray
function toRefs(object) {
if (!isProxy(object)) {
console.warn(`toRefs() expects a reactive object but received a plain one.`);
}
const ret = isArray(object) ? new Array(object.length) : {};
for (const key in object) {
ret[key] = toRef(object, key);
}
return ret;
}
const obj = {
a:4,
b:2
}
const result = toRefs(obj)
console.log(result)
这里提示了传入的object必须是一个reactive object 但是我们传了一个普通对象,还是可以运行的。
标签:toRefs,return,isReadonly,object,value,用法,vue3,const,isReactive 来源: https://blog.csdn.net/wx479/article/details/121093180