I need to update the Header.vue component from the ConfirmCode Component when the confirm method is called
When a user logs in with axios ajax, I want to refresh the li element of the header component
Appointment.vue:
<send-sms-modal@clickClose="setShowModal"
@clickSend="hideModal"
@clickConfirm="showStep=true"
:step="true"
:showRegister="showRegister"></send-sms-modal>
SendSMSModal.vue:
<confirm-code :mobile="mobileClone"
:user_id="userId" @clickConfirm="clickConfirm"
:step="step"></confirm-code>
<script>
clickConfirm() {
this.$emit('clickConfirm');
}
</script>
ConfirmCode.vue:
<button @click="confirm">
Confirm
</button>
<script>
confirm() {
axios.post('/api/confirm_code', {
confirm_code: this.code,
user_id: this.user_id}).then(function (response) {
if (response.data.status == true) {
window.localStorage.setItem('user', response.data.user);
this.$emit('clickConfirm');
}}.bind(this)).catch(function (error) {
this.errors = error.response.data.errors;
}.bind(this));
}
</script>
Header.vue:
<li>
<a v-if="user" href="">
User profile
</a>
<a v-else @click="setShowModal"
href="javascript:void(0)" class="">
<span>
Login
</span>
</a>
</li>
<script>
mounted() {
this.user = window.localStorage.getItem('user');
}
</script>