readonly bug?
Vue version
@vue/latest
Link to minimal reproduction
Steps to reproduce
const obj = {};
const arr = readonly([obj]);
console.log(arr.includes(obj)); // the result is false
What is expected?
expect to be true
What is actually happening?
this result is false
System Info
.
Any additional comments?
no
A readonly proxy is deep: any nested property accessed will be readonly as well. It also has the same ref-unwrapping behavior as reactive(), except the unwrapped values will also be made readonly.
To avoid the deep conversion, use shallowReadonly() instead.
https://vuejs.org/api/reactivity-core.html#readonly
const obj = {};
const arr = readonly([obj]);
Above code use readonly
the obj
will also reactive, so the arr.includes(obj)
is false.
You may need to use
shallowReadonly
or
toRaw