在ajaxtotalUserPosts返回零之后我遇到了这个问题,我不想要这个!
new Vue({
el: "#app",
data: {
totalUserPosts:0,
},
methods:{
getPostsAjax () {
$.ajax({
url:url,
type: 'get',
cache: false,
dataType: "json",
data:{
limit: this.limit,
id: this.vue_profile_id
}
}).done((data) => {
this.userPosts = data.posts;
this.totalUserPosts = data.total
}.bind(this))
},
getUserPosts () {
this.getPostsAjax()
$(window).scroll(() => {
if($(window).scrollTop() + $(window).height() > $(document).height() - 150) {
console.log(this.totalUserPosts)
}
})
}
})
我想在完成ajax请求后更改totalUserPosts,请帮助我
最佳答案
您在 ajax 函数返回之前调用滚动。您应该在 ajax 请求的回调函数中包含滚动功能,也许像这样:
new Vue({
el: "#app",
data: {
totalUserPosts:0,
},
methods:{
getPostsAjax () {
$.ajax({
url:url,
type: 'get',
cache: false,
dataType: "json",
data:{
limit: this.limit,
id: this.vue_profile_id
}
}).done(this.getUserPosts)
},
getUserPosts (data) {
this.userPosts = data.posts
this.totalUserPosts = data.total
$(window).scroll(() => {
if($(window).scrollTop() + $(window).height() > $(document).height() - 150) {
console.log(this.totalUserPosts)
}
})
}
},
ready () {
this.getPostsAjax();
}
})
关于javascript - 为所有人更改 Vuejs 中的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36861221/