I have a problem wanting to update the answers to a question that was asked, the detail is that when answering the question this answer is not updated in the answer list that is in the question.
I leave the code to be checked and they tell me what I'm doing wrong.
Response list of the question asked:
<div class="col-sm-12">
<replys v-for="reply in ask.replys" :reply="reply" :key="ask.id"></replys>
</div>
Form to answer the question
<div class="col-sm-12">
<reply-form v-on:answer="updateReplys" :ask="ask"></reply-form>
</div>
The components:
Here I post the questions with the answers given:
<script>
import Replys from './Replys.vue'
import ReplyForm from './ReplyForm.vue'
export default {
// Options / Data
created () {
this.getAskQuestion();
},
components: {
Replys,
ReplyForm
},
data () {
return {
replys: [],
askQuestions: [],
}
},
methods: {
updateReplys (replys) {
this.replys.push(replys);
},
getAskQuestion () {
axios.get('/paciente/questions')
.then(response => {
this.askQuestions = response.data.data;
});
}
},
}
</script>
Here the compiler Replys
<template lang="html">
<div class="col-md-10 col-md-offset-1 text-center-xs">
<div class="list-group-item md-whiteframe-z0 b-l-primary">
<a href="" class="pull-left w-40 m-r"><img :src="'/user/'+reply.user.id+'/photo'" class="img-responsive img-circle"></a>
<div class="clear">
<a href="" class="font-bold block"></a>
{{ reply.body }}
</div>
</div>
</div>
</template>
<script >
export default {
props: ['reply'],
}
</script>
Here the ReplysForm component
<template lang="html">
<div class="col-md-10 col-md-offset-1 text-center-xs">
<div class="list-group-item md-whiteframe-z0 b-l-success">
<a href="" class="pull-left w-40 m-r"><img :src="user.photo" class="img-responsive img-circle"></a>
<div class="clear">
<div class="md-form-group">
<form class="" action="" @submit.prevent="createComment(ask)">
<textarea class="md-input" rows="2" v-model="body"></textarea>
<button md-ink-ripple="" type="submit" class="md-btn md-flat m-b btn-fw text-info waves-effect">Responder</button>
</form>
</div>
</div>
</div>
</div>
</template>
<script lang="">
export default {
data () { return {
user: [],
body:[]
} },
props: ['ask'],
methods: {
getUser() {
axios.get('/user')
.then(response => {
this.user = response.data;
});
},
createComment(ask){
axios.post('/paciente/questions/replys',{body: this.body, ask_question_id: ask.id, user_id: user_id}).then(response => {
this.$emit('answer', response.data.replys);
this.body = ""
});
}
},
created () {
this.getUser()
},
}
</script>