I have a chile vue component and a property is passed as 'initial_features'
.
<child-component :initial_features="features"></child-component>
The code of my child component is:
<template>
<div class="container">
<div class="row justify-content-center">
<div class="col">
{{ initial_features }} //this prop is working here
</div>
</div>
</div>
</template>
<script>
export default {
props: ['initial_features'],
data() {
return {
features: this.initial_features, //undefined
}
},
methods: {},
computed: {},
mounted() {
console.log(this.initial_features); //output is undefined here
}
}
</script>
I have written this type of code many times but this time I am not getting the expected result. The props should work in the data or mounted section. Is there any mistake in my code?
features: null
inside your data and usecreated
function to copy it to your features. :) - halilcakardata
- Michal Levýundefined
- Yeasir Arafat Hridoydata(vm){ return{features: vm.initial_features,};}
? - Boussadjra Brahiminitial_features
prop and whats happening in parent component) butdata
function is called only once when component is created so if prop is updated later, it has no effect onfeatures
indata
unless your passing object/array and updating that object/array instead of replacing it (which is not the case here because initial value isundefined
). Add the code of parent and more details.. - Michal Levý