var app = new Vue({ el: "#app", data: function () { return { useType: 1, allCoupon: [{ useType: 1, page: 0, limit: 10, data: [], hasMore: 1 }, { useType: 2, page: 0, limit: 10, data: [], hasMore: 1 }, { useType: 3, page: 0, limit: 10, data: [], hasMore: 1 }], couponData: [] } }, methods: { changeUseType(useType) { this.useType = useType; if (this.allCoupon[useType - 1]['data'].length == 0 || this.allCoupon[useType - 1]['hasMore'] == 1) { this.loadMore(); } else { this.couponData = this.allCoupon[useType - 1]['data']; } }, getData(useType, page) { $.ajax({ url: '/index.php/vip/coupon/getcoupondata', data: { type: useType, page: page }, type: "post", success: (res) => { if (res.status == 1) { this.allCoupon[useType - 1]['page'] = page; this.allCoupon[useType - 1]['data'] = this.allCoupon[useType - 1]['data'].concat(res.data); this.$nextTick(() => { this.couponData = this.allCoupon[useType - 1]['data']; this.allCoupon[useType - 1]['hasMore'] = res.data.length == 10 ? 1 : 2 }) } else { this.allCoupon[useType - 1]['hasMore'] = 2; this.couponData = this.allCoupon[useType - 1]['data']; } }, error: (error) => { alertMsg('出错了'); } }) }, loadMore() { this.getData(this.useType, this.allCoupon[this.useType - 1].page + 1); }, toDetails(id) { window.location.href = '/index.php/vip/coupon/coupondetail?id=' + id; } }, created() { this.getData(1, 1); } })