在 Vuejs 中为所有人更改数据

change data in Vuejs for all

本文关键字:数据 所有人 Vuejs      更新时间:2023-09-26

在 ajax totalUserPosts 返回我 Zero 后,我对此有问题,我不想要这个!

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 请求后更改总数用户帖子请帮助我

你在 ajax 函数返回之前调用 scroll。 您应该在 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();
        }
    })