I have a problem with a simple function, I'm not understanding where is the problem. I'm working on Vue.
setup(props) {
console.log('sono setup')
const state = reactive({
myMenu5: [],
myMenuTry: [
{
title: 'Home',
route: 'home',
icon: 'HomeIcon',
},
{
title: 'Second Page',
route: 'second-page',
icon: 'FileIcon',
},
],
})
onMounted(() => {
console.log('sono su onMounted')
async function getMenu() {
await axios.get('https://jsonplaceholder.typicode.com/posts').then(res => {
state.myMenu5.push(JSON.parse(JSON.stringify(res.data)))
console.log('res1', res.data)
}).catch(err => console.log(err))
}
getMenu()
// state.myMenu5 = JSON.parse(JSON.stringify(state.myMenu5))
console.log('myMenu5', state.myMenu5)
const ciao = JSON.parse(JSON.stringify(state.myMenu5))
console.log('ciao', ciao)
})
This is my component and my reactive myMenu5 when I populate inside the function getMenu give me this result:
myMenu5 [__ob__: Observer]
0: (100) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, __ob__: Observer]
length: 1
__ob__: Observer {value: Array(1), dep: Dep, vmCount: 0}
__proto__: Array
How to convert to Array? I'm blocked here. I searched to other posts but every solution not worked for me. Thank you