When vue3 gets the object in vuex, it is the proxy object, how to get the value

When using vuex, it is found that when you get the variable of type string number of state, you can get the value directly through store.state.value, but when you get the object, the console prints the Proxy object, which is inside the Proxy object. [[Target]] is the real object.
proxy object

//第一种获取target值的方式,通过vue中的响应式对象可使用toRaw()方法获取原始对象
import { toRaw } from '@vue/reactivity'
var list = toRaw(store.state.menuList)

insert image description here

//第二种获取target值的方式,通过json序列化之后可获取值
JSON.parse(JSON.stringify(store.getters.menuList))

Update: I recently encountered a small problem when using toRaw. Using this method will cause the data to be updated but the view will not be updated. Although the proxy object is taken out from vue, it can also directly perform array operations, such as splice. , array expansion, etc.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=324125949&siteId=291194637