Answer the question
In order to leave comments, you need to log in
Why isn't a method called from another method in vue?
It works, but somehow I don't want to duplicate the code...
let data = function() {
return { user: {}};
};
vm = new Vue({
el: '#navbar',
data: data,
methods: {
getUserInfo: function() {
let vm = this;
$.ajax({
type: 'GET',
url: config.apiHost + apiRoutes.getUserInfo,
dataType: 'json',
})
.done(function(res) {
if (!res.error) {
vm.user = res.data;
}
});
},
loginLocal: function() {
let vm = this;
let res = this.sendForm('loginLocal') /*для простоты убрал код функции sendForm*/
.done(function(res){
if (!res.error) {
vm.user = res.data;
}
});
},
logout: function(e) {
let vm = this;
let res = this.sendForm('logout')
.done(function(res){
if (!res.error) {
vm.user = res.data; // /*тоже самое, что */ vm.user = {};
}
});
},
}
});
let data = function() {
return { user: {}};
};
vm = new Vue({
el: '#navbar',
data: data,
methods: {
getUserInfo: function() {
let vm = this;
$.ajax({
type: 'GET',
url: config.apiHost + apiRoutes.getUserInfo,
dataType: 'json',
})
.done(function(res) {
if (!res.error) {
vm.user = res.data;
}
});
},
loginLocal: function() {
let vm = this;
let res = this.sendForm('loginLocal') /*для простоты убрал код функции sendForm*/
.done(function(){ // пробовал просто "getUserInfo() или getUserInfo"
getUserInfo();
});
},
logout: function(e) {
let vm = this;
let res = this.sendForm('logout')
.done(function(){
getUserInfo();
});
},
}
});
Answer the question
In order to leave comments, you need to log in
vm.$set(vm,'user',res.data)
Why jq for ajax? fetch, axios - for wimps?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question