vue 一个页面根据状态渲染不同的组件 使用currentView动态渲染

1.在当前vue页面导入所需要的组件
组件目录:
在这里插入图片描述
:index.vue就是要渲染的页面
在data中定义变量:
在这里插入图片描述

components: {
    submitVeterans: () => import("./submitVeterans"),
    veteransWait: () => import("./veteransWait"),
    veteransFail: () => import("./veteransFail"),
    veteransSuccess: () => import("./veteransSuccess"),
  },

2.根据接口返回的状态值渲染不同的组件
在这里插入图片描述
3.完整代码

<template>
  <div class="appoint">
    <div :is="currentView" @getStatus="getStatus"></div>
  </div>
</template>

<script>
import { getMyApply } from "@/api/course";
export default {
  components: {
    submitVeterans: () => import("./submitVeterans"),
    veteransWait: () => import("./veteransWait"),
    veteransFail: () => import("./veteransFail"),
    veteransSuccess: () => import("./veteransSuccess"),
  },
  data() {
    return {
      currentView: "",
      status: "", // 状态值
      token:
        "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX25hbWUiOiIxNzYzMDIxNjAyNCIsInNjb3BlIjpbImFsbCJdLCJuaWNrbmFtZSI6IlBPUE_mjqLntKLogIU5NTIiLCJpZCI6MTM0NjcyNDIxMjc1NjgyODE2MiwiZXhwIjoxNjI4MTQ0MjUzLCJqdGkiOiI4MmQzNTc1OC1mNDNkLTQ1YTMtYTA3MS1hZGUwNWY4NGQ0OTkiLCJjbGllbnRfaWQiOiJwb3J0YWwtYXBwIn0.hodSrrsplqOfMrUJ6aVSLMdnS93flc0uhR-lB5d0gZBi_6ApJkOES0zf0SUzxPxAimoPQfRZ3I9X_rzunWJMgNCXNdjKcIhDtn08o24Cc89_j8mWityp_NAgBI6S0LYynEM0lxLdyeuLIXoqjYclIBBXeM_lDFtBBAGaAFdjHII",
      //   token: "",
    };
  },
  created() {
    this.getactivity();
  },

  methods: {
    getactivity() {
      getMyApply(this.token).then((res) => {
        console.log(res);
        console.log(res.data.code);
        if (res.data.code == 200) {
          //获取他的返回值 用返回值判断
          if (this.status == 1) {
            //   显示页面:提交资料
            this.currentView = "submitVeterans";
            //     显示页面:审核失败
            // this.currentView = "veteransFail";
          } else if (this.status == 2) {
            //   显示页面:审核中
            this.currentView = "veteransWait";
          } else if (this.status == 3) {
            //  显示页面:审核成功
            this.currentView = "veteransSuccess";
          } else {
            //   显示页面提交资料
            this.currentView = "veteransFail";
          }
        }
      });
    },
    
  },
};
</script>
<style lang="scss" scoped>
* {
  margin: 0;
  padding: 0;
}
</style>

注:该文章只是自己开发时的记录。

  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值