I thought passing an Object is simillar to an array, I just simply need to avoid v-for loop. But in this case I'm getting prop as an undefined.
<template>
<p>{{info.text...}}</p>
</template>
export default {
props: {
info: {
type: Object,
default: () => ({})
}
},
mounted () {
console.log(this.info) // gets undefined
}
}
Passing an object as a prop in Vue.js is similar to passing other types of props, but there might be an issue with how you are using it.
First, make sure you are correctly passing the
infoprop from the parent component to the child component in the template where the child component is used.For example, if you are using the child component in the parent component's template, you should pass the
infoprop like this:Next, make sure that the
infoObjectexists and is defined in the parent component's data.Now, in your child component, you can access the
infoprop and use it as follows:By following these steps, you should be able to pass an object as a prop and access its properties in your child component. If you are still getting
undefined, please double-check that you are correctly passing the prop from the parent component and that the object is defined with the appropriate properties.