vue3 reactive toRaw
时间: 2023-08-17 19:11:13 浏览: 105
`toRaw` is a function in Vue 3's `@vue/reactivity` package that returns the original raw reactive object of a proxy created by the `reactive` function.
In Vue 3, when you use the `reactive` function to create a reactive object, it wraps the original object in a proxy. The `toRaw` function allows you to access the original raw object from the proxy.
Here's an example usage:
```javascript
import { reactive, toRaw } from 'vue';
const obj = reactive({ foo: 'bar' });
const proxy = toRaw(obj);
console.log(proxy.foo); // Output: bar
console.log(obj === proxy); // Output: false
```
In the example above, the `obj` is a reactive object created using `reactive`. When we call `toRaw(obj)`, it returns the original raw object, which is equivalent to `{ foo: 'bar' }`. Note that `obj` and `proxy` are not the same object, but they have the same values.
This function can be useful in certain scenarios where you need to access the original object or perform operations that are not supported on proxies but are supported on raw objects.
阅读全文