Answer the question
In order to leave comments, you need to log in
How to re-render a vue component?
I have a Header.vue component that contains the site header.
<div class="main_menu__auth l-ml-10 lm-ml-10" ref="map">
<div v-if="authdata == null" class="main_menu__auth__login l-fs-15 main_menu__auth__login--shown">
<i class="far fa-user-circle l-fs-20 icon icon--signin"></i>
<span class="l-ml-10 lm-hidden">Войти</span>
</div>
<div v-else>
{{authdata.name}} |
<button @click="exit">Выход</button>
</div>
</div>
export default {
data:function(){
return{
}
},
props:[
'authdata'
],
mounted(){
this.update()
},
watch:{
},
methods:{
update: function () {
console.log(this.authdata)
},
exit:function () {
$.ajax({
url: "/exit",
type: "GET",
data: "get=on",
success: function (response) {
console.log('Нажал на выход'+response);
this.authdata = null;
console.log(this.authdata);
}
});
}
}
}
Answer the question
In order to leave comments, you need to log in
You seem to be doing everything right, but:
exit:function () {
let t = this; // вам нужно передать внутрь правильный контекст
$.ajax({
url: "/exit",
type: "GET",
data: "get=on",
success: function (response) {
console.log('Нажал на выход'+response);
t.authdata = null; // внимание! this здесь уже не тот! :)
console.log( t.authdata);
}
});
}
Incoming properties cannot be nulled from a component. You should have an error in the console saying that you can't do that.
For things like this, use vuex to push the data globally.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question