普通,显示“正在加载”
-
request() {
let data = {
id: "1000001"
};
console.log(data);
this.$vux.loading.show({ text: "正在加载" });
this.$api.indexInterface.requestData(data)
.then(res => {
this.$vux.loading.hide();
res = res.data;
if (res.success) {
this.list = res.data;
} else {
this.$vux.toast.show({ type: "cancel", text: "加载失败" });
}
})
.catch(err => {
this.$vux.loading.hide();
console.error(err);
});
},
复制代码
-
this.$api.indexInterface.requestData({
id: "1000001"
}).then(res => {
res = res.data;
if (res.success) {
this.table.count = res.data.count;
this.table.body = (() => {
let arr = [];
[...res.data.dbPageList].map(m => arr.push(m));
return arr;
})();
} else {
this.$vux.toast.show({ type: "cancel", text: "加载失败" }); //res.retMsg
}
}).catch(err => console.error(err))
复制代码
Promise封装
const promise = new Promise((resolve, reject) => {
this.$api.indexInterface.requestData({
id: "1000001"
}).then(res => {
res = res.data;
res.success ? resolve(res.data) : reject(res.retMsg);
}).catch(err => console.error(err))
});
promise.then(resolve => {
[...resolve].map(m => this.table.body.push(m));
}, reject => {
console.error(reject);
})
复制代码
复制代码