<template>
  <div id="app" style="height: 100%; width: 100%">
    <router-view v-if="examInfo.exam_id"></router-view>
  </div>
</template>

<script>
import { getExamInfo } from '@/api/base.js'

export default {
  metaInfo() {
    return {
      title: this.examInfo.name || ''
    }
  },
  computed: {
    examId() {
      return this.$route.params.examId || this.$route.query.exam_id
    },
    examInfo() {
      return this.$store.state.examInfo || {}
    }
  },
  watch: {
    examId: {
      immediate: true,
      handler() {
        this.fetchExamInfo()
      }
    }
  },
  methods: {
    fetchExamInfo() {
      if (!this.examId) return
      getExamInfo(this.examId).then(res => {
        this.$store.commit('setExamInfo', res)
      })
    }
  }
}
</script>
