针对一个页面多个相同的API接口,只是参数不同的简单写法:
ready () {
this.$set('url', '/api/merchants/' + window.user.merchantId + '/users/' + window.user.id + '/items')
var that = this
this.$set('ajax', function (a, s) {
that.$http.get(that.url, s).then(function (response) {
if (response.data.userItems.length > 0) {
that.$set(a, response.data)
} else {
$.alert('暂无数据')
}
})
})
let _status = {status: 0}
this.ajax('data', _status)
},
methods: {
consumed: function () {
let status = {status: 1}
this.ajax('items', status)
},
expire: function () {
let status = {status: 2}
this.ajax('items1', status)
}
}