使用v-if
来控制
- 先设置
showCard
为false
,内容card
为""
- 请求成功后设置
showCard
为true
,内容card
为请求得到的数据res.data
<div v-if="showCard"><div>
data() {
return {
card:"",
showCard:false,
}
}
created() {
this.$vux.loading.show({ text: "正在加载" });
this.$api.cardInterface
.getCard({
// cardId:"001"
})
.then(res => {
this.$vux.loading.hide();
console.log(res);
if (res.data.success) {
this.showCard = true;
this.card = res.data;
} else {
this.$vux.toast.show({ type: "cancel", text: "提交失败" });
}
})
.catch(err => {
this.$vux.loading.hide();
this.$vux.toast.show({ type: "warn", text: "Request failed" });
console.error(err);
});
复制代码
所有评论(0)