<template>
  <template v-if="component == null">错误类型数据</template>
  <component v-else ref="component" :is="component" :value="value"/>
</template>

<script>
const map = {
  IMAGE: 'ImagePreview',
  LINK: 'LinkPreview',
  IMAGE_LINK: 'ImageLinkPreview'
}
import ImagePreview from './ImagePreview'
import LinkPreview from './LinkPreview'
import ImageLinkPreview from './ImageLinkPreview'
export default {
  name: 'ResourcePreview',
  components: {
    ImagePreview,
    LinkPreview,
    ImageLinkPreview
  },
  props: {
    // 资源类型
    type: {
      required: true
    },
    // 资源值
    value: {
      required: true
    }
  },
  computed: {
    component () {
      return this.$options.components[map[this.type]]
    }
  },
}
</script>
