Getting value of array property #509
Replies: 4 comments 7 replies
-
That doesn't sound right, Proxies are transparent to underlying object type. In any case to solve this issue you can try the following:
You might be able to use Alpine |
Beta Was this translation helpful? Give feedback.
-
I am seeing behavior like this too. My arrays come back as a Proxy, which causes all kinds of issues. Is this normal? I'm running quite an old Webpack build so something could be going wrong in the compiler. |
Beta Was this translation helpful? Give feedback.
-
I think my solution was not a best practice but for me, if I need to get the Array value that was initiated in the state, then I need to store the state in localStorage and to sync with it i will put in the watch effect at init function foo: [{ id : 1, title : "bar" }, { id : 2, title : "bar" }]
init() {
this.$watch("foo", () => {
localStorage.setItem("foo", JSON.Stringify(foo))
})
}, so when my function need the array value i could get from localStorage triggerSomething(){
const foo = JSON.parse(localStorage.getItem("foo"))
foo.map(item => {
console.log(item.title)
})
} |
Beta Was this translation helpful? Give feedback.
-
The best answer, is that Alpinejs uses vue reactivity, and vue reactivity provides a So just do
But Actually, EVEN BETTER!!!
That is the appropriate way to do it :D |
Beta Was this translation helpful? Give feedback.
-
I have an array property and when I try to save it to another storage, it it saved as an object instead of array.
How can I get the real value of the items property instead of the Proxy object?
Beta Was this translation helpful? Give feedback.
All reactions