Looking for a solution with my component that receives data, I have the following setup in my controller:
route::get('/', function() { return inertia('foo', ['data' => Model::all()]) });
Within my Vue component:
<template>
<ul>
<li v-for="item in data">{{item.name}}</li>
</ul>
</template>
<script setup>
defineProps({ data: Object })
</script>
My objective is to display the data based on either name
or score
depending on a checkbox value. Rather than making a server-side request, I'm exploring options to handle this within the component itself.
However, it seems that props are read-only, preventing me from implementing something like this:
<li v-for="Object(data).sort((a, b) => b.score - a.score)">
Do you have any other suggestions?
The type of props.data
is as follows:
Proxy {0: {…}, 1: {…}, 2: {…}, 3: {…}, 4: {…}, 5: {…}, 6: {…}, 7: {…}, 8: {…}, 9: {…}, 10: {…}, 11: {…}, 12: {…}, 13: {…}, 14: {…}, 15: {…}, 16: {…}}
[[Handler]]: Object
[[Target]]: Object
0: {id: 1, user: null, name: 'foobar', score: 0, …}
1: {id: 2, user: null, name: 'baz', score: 10, …}
And it appears that Object(props.data)
does not support a sort
method.