If you forgot to declare the props in your component x
as shown below:
//x.vue
<script>
export default {
props : ['a']
}
</script>
The component won't recognize the props that are passed to it and they will remain undefined.
But don't worry, you can still pass a complete object as a prop to the component like this:
/*
const obj = {
a: 1,
b: 2,
c: 3
}
*/
<x :dynprop="obj" />
<script>
export default {
props : ['dynprop'],
mounted() {
console.log(dynprop.a);
// Output: 1
}
}
</script>
For more information on passing objects as props, refer to the official Vue Docs: https://v2.vuejs.org/v2/guide/components-props.html#Passing-the-Properties-of-an-Object
This method is recommended because:
Vue does not allow dynamically adding new root-level reactive properties to an already created instance.