使用vue製做加載更多功能,經過ajax獲取的數據往data裏面push常常不成功,緣由是push是往數組中追加數據內容的,而不能用做數組之間的拼接,ajax獲取的數據就是數組形式的,所以不成功,應該使用concat()拼接兩個數組。vue
//這是錯誤的寫法 $.ajax({ type:'get', async:false, url:path+'no/noticeMobile/getSendNoticeList?imToken='+ getToken +'&pageFlag=2', dataType: "json", success: function(msg){ _self.$set('loadMore', msg); _self.conList.push(_self.loadMore); } });
//這是正確的寫法 $.ajax({ type:'get', async:false, url:path+'no/noticeMobile/getSendNoticeList?imToken='+ getToken +'&pageFlag=2', dataType: "json", success: function(msg){ _self.$set('main',_self.main.concat(msg)) } });
模擬ajax數據加載測試地址:https://jsfiddle.net/zhoou/96...ajax
總結:仍是本身js基礎知識不紮實,push和concat兩個函數用法沒有搞清楚,若是你有更好的方法歡迎討論。json