PromiseSpan.vue 622 Bytes
Newer Older
Anton's avatar
Anton committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
<template lang="pug">
    span(v-if="display") {{ display }}
</template>

<script>
  export default {
    name: 'PromiseSpan',
    props: ['value'],
    data () {
      return {
        display: undefined
      }
    },
    mounted () {
      this.resolveValue()
    },
    methods: {
      resolveValue () {
        const _this = this
        if (this.value instanceof Promise) {
          this.value.then(v => { _this.display = v })
        }
        else if (typeof this.value === 'string') _this.display = this.value
      }
    },
    watch: {
      value () {
        this.resolveValue()
      }
    }
  }
</script>