Hi i have two component , I get response in one component and need to pass and push in the array of parent component. Below is my code. I have not received response.
In Userstatuscomponent.vue I have few methods and whatever response I get there I want to pass this to UserComponent.vue and push it in users[] array. I think I have done something wrong. Please help me.
UserComponent.vue
<template>
<div>
<Status v-on:updateStatus="receiveResponse(userData)"></Status >
<div class="card" >
<div class="card-header">
<div class="card-body" v-for="user in users.data" >
</div>
</div>
</div>
</div>
</template
<script type="application/javascript">
import Status from '../components/UserstatusComponent.vue'
export default {
data() {
return {
users: [],
};
},
created() {
this.getResult();
},
components: {
Filter
},
methods: {
getResult() {
axios
.get("/api/result")
.then(response => {
this.users = response.data;
})
.catch(error => console.log(error));
},
receiveResponse(userData){
this.users = userData
},
//HERE I HAVE RECEIVED THE EVENT and update users array
receiveResponse(user){
this.users = user
},
}
};
</script>
Now I have some method in UserStatusComponent and I want to pass the response from this component to UserComponent.vue
UserstatusComponent.vue
<template>
<div class="">
<a
@click.prevent="updateOne"
>update one</a
>
<a
@click.prevent="updateTwo"
>update two</a
>
</div>
</div>
</div>
</template>
<script>
export default {
data(){
return{
}
},
updateOne() {
axios
.get("/api/result", {
params: {
status: "bad"
}
})
.then(response => {
this.$emit('updateStatus',response.data);
});
},
updateTwo() {
axios
.get("/api/result", {
params: {
stauts: "good"
}
})
.then(response => {
this.$emit('updateStatus',response.data);
});
},
}
</script>